For simplicity, this answer is for the scalar field. The argument for the electromagnetic field is similar.
The energy of an electromagnetica Scaler field looks something like:
$$\int d^3x (\pi^2+ |\vec{\nabla \phi}| ^2 + m^2\phi^2)$$
This mathematically looks like a bunch of coupled Harmonic oscillators. You can do a Fourier transform to make it look like a bunch of decoupled Harmonic oscillators:
$$\int d^3p \omega_{\vec{p}} a^{\dagger}_{\vec{p}} a_{\vec{p}}$$ .... (1)
where $\omega_{\vec{p}}=\sqrt{|\vec{p}|^2+m^2}$
The main point is that, just like how the position of an electron can be bound to the origin using the oscillator attractive force $-m\omega^2x$, you can interpret the Maxwell's equationsfield equation in such a way that that the field strength at a point is bound using an "attractive force" whose mathematical form is similar to an oscillator force.
I say "attractive force" in quotes because no one would use the word "force" to describe this phenomenon. What's really happening is that the field strength tries to bounce back to 0 if it deviates from there. This is a consequence of Maxwell's equationsthe field equation. TheYou can see that the Hamiltonian I wrote in the beginning produces the same dynamics as Maxwell's equations. You can see that it has a quadratic term $m^2\phi^2$. This term is similar to the Harmonic oscillator potential $V=x^2$. Terms like this result in an attractive force according to $F=-\frac{dV}{dx}=-x$. However, this isn't some external force in the case of the electromagnetic field. The free field Maxwell's equations have this mathematical behavior.
Now, equation $(1)$ represents the energy of an infinite number of decoupled Harmonic oscillators of a continuous range of frequences. When you quantise this, the energy of each oscillator gets discretized according to $E=n\hbar \omega_{\vec{p}}$. The total energy of the field, which is integral of the energies of each oscillator, is not discretized because the oscilators have a continuous range of frequences.