When an electromagnetic field is quantized, the field energy becomes discontinuous and will consist of discrete energy parcels, photons. Photons are massless particles of definite energy, definite momentum, and definite spin.
In order to explain the photoelectric effect, Einstein postulated in 1905 that an electromagnetic field consists of parcels of energy hν, where h is Planck's constant. In 1927 Paul A. M. Dirac was able to fit the photon concept into the framework of the new quantum mechanics. He applied a technique which is now generally called second quantization,[1] although this term is somewhat of a misnomer for EM fields, because they are, after all, solutions of the classical Maxwell equations, and it is the first time that they are quantized.
Second quantization
Second quantization starts with an expansion of a field in a basis consisting of a complete set of functions. The coefficients multiplying the basis functions are then interpreted as operators and (anti)commutation relations between these new operators are imposed, commutation relations for bosons and anticommutation relations for fermions (nothing happens to the basis functions themselves). By doing this, the expanded field is converted into a fermion or boson operator field. The expansion coefficients have become creation and annihilation operators: a creation operator creates a particle in the corresponding basis function and an annihilation operator annihilates a particle in this function.
In the case of EM fields the required expansion of the field is the Fourier expansion.
Quantization of EM field
The best known example of quantization is the replacement of the time-dependent linear momentum of a particle by the rule
.
Note that Planck's constant is introduced here and that time disappears (in the so-called Schrödinger picture).
For the EM field we do something similar and apply the quantization rules:

subject to the boson commutation relations
![{\displaystyle {\begin{aligned}{\big [}a^{(\mu )}(\mathbf {k} ),\,a^{(\mu ')}(\mathbf {k} '){\big ]}&=0\\{\big [}{a^{\dagger }}^{(\mu )}(\mathbf {k} ),\,{a^{\dagger }}^{(\mu ')}(\mathbf {k} '){\big ]}&=0\\{\big [}a^{(\mu )}(\mathbf {k} ),\,{a^{\dagger }}^{(\mu ')}(\mathbf {k} '){\big ]}&=\delta _{\mathbf {k} ,\mathbf {k} '}\delta _{\mu ,\mu '}.\end{aligned}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/3a5d991b681917bd5b9ea89d1c793762c8b44fa5)
The square brackets indicate a commutator, defined by
![{\displaystyle {\big [}A,B{\big ]}\equiv AB-BA}](https://wikimedia.org/api/rest_v1/media/math/render/svg/9187ec2904b6400b5475bbbabeac32667b23be0f)
for any two quantum mechanical operators A and B.
The quantized fields (operator fields) are the following

where ω = c |k| = ck.
Hamiltonian of the field
Substitution of the operators into the classical Hamiltonian gives the Hamilton operator of the EM field

By the use of the commutation relations the second line follows from the first. Note that
ℏω = h ν = ℏ c |k|,
which is the well-known Einstein expression for photon energy. Remember that ω depends on k, even though it is not explicit in the notation. The notation ω(k) could have been introduced, but is not common.
Digression: harmonic oscillator
The second quantized treatment of the one-dimensional quantum harmonic oscillator is a well-known topic in quantum mechanical courses. We digress and say a few words about it. The harmonic oscillator Hamiltonian has the form

where ω ≡ 2πν is the fundamental frequency of the oscillator. The ground state of the oscillator is designated by | 0 ⟩ and is referred to as vacuum state. It can be shown that
is an excitation operator, it excites from an n fold excited state to an n+1 fold excited state:

Since harmonic oscillator energies are equidistant, the n-fold excited state | n⟩ can be looked upon as a single state containing n particles (sometimes called vibrons) all of energy hν. These particles are bosons. For obvious reason the excitation operator
is called a creation operator.
From the commutation relation follows that the Hermitian adjoint
de-excites:

because a function times the number 0 is the zero function. For obvious reason the de-excitation operator
is called an annihilation operator.
Suppose now we have a number of non-interacting (independent) one-dimensional harmonic oscillators, each with its own fundamental frequency ωi. Because the oscillators are independent, the Hamiltonian is a simple sum:

Making the substitution

we see that the Hamiltonian of the EM field can be looked upon as a Hamiltonian of independent oscillators of energy ω = |k| c and oscillating along direction e(μ) with μ=1,−1.
Photon energy
The quantized EM field has a vacuum (no photons) state | 0 ⟩. The application of, say,

gives a quantum state of m photons in mode (μ, k) and n photons in mode (μ', k'). We use the proportionality symbol because the state on the right-hand is not normalized to unity.
We can shift the zero of energy and rewrite the Hamiltonian as

The operator
is the number operator. When acting on a quantum mechanical photon state, it returns the number of photons in mode (μ, k). Such a photon state is an eigenstate of the number operator. This is why the formalism described here, is often referred to as the occupation number representation.
The effect of H on a single-photon state is

Apparently, the single-photon state is an eigenstate of H and
is the corresponding energy.
Example photon density
In this article the electromagnetic energy density was computed that a 100kW radio station creates in its environment; at 5 km from the station it was estimated to be 2.1·10−10 J/m3. Is quantum mechanics needed to describe the broadcasting of this station?
The classical approximation to EM radiation is good when the number of photons is much larger than unity in the volume

where λ is the length of the radio waves. In that case quantum fluctuations are negligible and cannot be heard.
Suppose the radio station broadcasts at ν = 100 MHz, then it is sending out photons with an energy content of νh = 1·108× 6.6·10−34 = 6.6·10−26 J, where h is Planck's constant. The wavelength of the station is λ = c/ν = 3 m, so that λ/(2π) = 48 cm and the volume is 0.111 m3. The energy content of this volume element is 2.1·10−10 × 0.111 = 2.3 ·10−11 J, which amounts to
- 3.5 ·1012 photons per

Obviously, 3.5 ·1012 is much larger than one and hence quantum effects do not play a role; the waves emitted by this station are well into the classical limit, even when it plays non-classical music, for instance of Led Zepplin.
Photon momentum
Introducing the operator expansions for E and B into the classical form

yields

The 1/2 that appears can be dropped because when we sum over the allowed k, k cancels with −k.
The effect of PEM on a single-photon state is

Apparently, the single-photon state is an eigenstate of the momentum operator, and
is the eigenvalue (the momentum of a single photon).
Photon mass
The photon having non-zero linear momentum, one could imagine that it has a non-vanishing rest mass m0, which is its mass at zero speed. However, we will now show that this is not the case: m0 = 0.
Since the photon propagates with the speed of light, special relativity is called for. The relativistic expressions for energy and momentum squared are,

From p2/E2,

Use

and it follows that

so that m0 = 0.
Photon spin
The photon can be assigned a triplet spin with spin quantum number S = 1. This is similar to, say, the nuclear spin of the 14N isotope, but with the important difference that the state with MS = 0 is zero, only the states with MS = ±1 are non-zero.
We define spin operators:

The products between the unit vectors on the right-hand side are dyadic products. The unit vectors are perpendicular to the propagation direction k (the direction of the z axis, which is the spin quantization axis).
The spin operators satisfy the usual angular momentum commutation relations
![{\displaystyle [S_{x},\,S_{y}]=i\hbar S_{z}\quad {\hbox{and cyclically}}\quad x\rightarrow y\rightarrow z\rightarrow x.}](https://wikimedia.org/api/rest_v1/media/math/render/svg/37c218e5b0d6a020decb90159880c8d187b4d401)
Indeed,
![{\displaystyle [S_{x},\,S_{y}]=-\hbar ^{2}{\Big (}\mathbf {e} _{y}\mathbf {e} _{z}-\mathbf {e} _{z}\mathbf {e} _{y}{\Big )}\cdot {\Big (}\mathbf {e} _{z}\mathbf {e} _{x}-\mathbf {e} _{x}\mathbf {e} _{z}{\Big )}+\hbar ^{2}{\Big (}\mathbf {e} _{z}\mathbf {e} _{x}-\mathbf {e} _{x}\mathbf {e} _{z}{\Big )}\cdot {\Big (}\mathbf {e} _{y}\mathbf {e} _{z}-\mathbf {e} _{z}\mathbf {e} _{y}{\Big )}=i\hbar {\Big [}-i\hbar {\big (}\mathbf {e} _{x}\mathbf {e} _{y}-\mathbf {e} _{y}\mathbf {e} _{x}{\big )}{\Big ]}=i\hbar S_{z}.}](https://wikimedia.org/api/rest_v1/media/math/render/svg/0db8a4cccd4be7e404d326a731eb7c4ce7651a2f)
Define states

By inspection it follows that

and correspondingly we see that μ labels the photon spin,

Because the vector potential A is a transverse field, the photon has no forward (μ = 0) spin component.
- ↑ The name derives from the second quantization of quantum mechanical wave functions. Such a wave function is a scalar field: the "Schrödinger field" and can be quantized in the very same way as EM fields. Since a wave function is derived from a "first" quantized Hamiltonian, the quantization of the Schrödinger field is the second time quantization is performed, hence the name.