For free electromagnetic fields, it is possible to choose a gauge such that the scalar potential $\phi(t,{\bf x})=0$ and the vector potential ${\bf A}(t,{\bf x})$ satisfies the Coulomb gauge condition $\nabla\cdot{\bf A}(t,{\bf x})=0$. If the Fourier amplitudes of the spatial Fourier transform of ${\bf A}(t,{\bf x})$ are denoted by $\tilde{\bf A}_{\bf k}$, the latter condition is equivalent to $${\bf k}\cdot\tilde{\bf A}_{\bf k}=0,~~ \text{for each} ~{\bf k}.\tag{1}$$ Therefore, the $\tilde{\bf A}_{\bf k}$ vector is confined to a plane transverse to ${\bf k}$, and therefore has two independent components. This explains why there are two independent degrees of freedom! But $(1)$ is true for each ${\bf k}$ and there are infinitely many ${\bf k}$ in the Fourier decomposition of ${\bf A}(t,{\bf x})$.
Why doesn't that make the number of degrees of freedom from two to infinitely many?