Key space math clarification The following table specifies a cryptosystem based around a very simple encryption algorithm with four different plaintexts A, B, C and D (one corresponding to each row) and four different ciphertexts A, B, C and D. The encryption algorithm has five different keys K1, K2, K3, K4, K5 (one corresponding to each column). By writing EK(P)=C to mean that the encryption of plaintext P using encryption key K is C, the entire cryptosystem is defined as follows:

EK1(A)=B   EK2(A)=B   EK3(A)=D   EK4(A)=A  EK5(A)=C
EK1(B)=C   EK2(B)=C   EK3(B)=B   EK4(B)=B  EK5(B)=D
EK1(C)=D   EK2(C)=A   EK3(C)=A   EK4(C)=D  EK5(C)=A
EK1(D)=A   EK2(D)=D   EK3(D)=C   EK4(D)=C  EK5(D)=B


I am getting conflicted on this question. To me the key space should be 5. But some articles I've read say you do do k^2. If this was the case it would be k^5 = 32. Does it change how you compute this based on the algorithm or? I'm stumped.

This is not school related. I'm just wanting to learn some security and failing lol
the key space should be 5


Something is $5$, but that's not the key space.

The key space is the set $\{\mathtt{K1},\mathtt{K2},\mathtt{K3},\mathtt{K4},\mathtt{K5}\}$. We'll note it $\mathcal K$.

The size of the key space (or key space size for short) $\|\mathcal K\|$ is $5$.

The size of the key (or key size for short) in bits, that we'll note $k$, is the base-2 logarithm of the size of the key space, that is $k=\log_2(\|\mathcal K\|)$.
Here $k=\log_2(5)=\log(5)/\log(2)=2.3219\ldots$ bit.


  But some articles I've read say you do do $k^2$.


Read again: probably the article says that the size $\|\mathcal K\|$ of the key space $\mathcal K$ is $2^k$, where $k$ is the size of the key in bits. That is, $\|\mathcal K\|=2^k$. Or equivalently, $k=\log_2(\|\mathcal K\|)$.