Consider a short length ¡ near the middle of a long, tightly wound solenoid, of cross-sectional area A, number of turns per unit length n and carrying a steady current I. For such a solenoid, the magnetic field is approximately uniform everywhere inside and zero outside. So, the magnetic energy Um stored by this length l of the solenoid lies entirely within the volume Al.
The magnetic field inside the solenoid is B = µ0nI …………… (1)
and if L be the inductance of length l of the solenoid,
L = µ0n2 lA …………… (2)
The stored magnetic energy,
Um = \(\cfrac12\) LI2 …………. (3)
and the energy density of the magnetic field (energy per unit volume) is
Um = \(\cfrac{U_m}{AI}\) = \(\cfrac12\)\(\cfrac{LI^2}{Al}\)......(4)
Substituting for L from Eq. (2)

Equation (6) gives the magnetic energy density in vacuum at any point in a magnetic field of induction B, irrespective of how the field is produced.
[Note : Compare Eq.(6) with the electric energy density in vacuum at any point in an electric field of intensity
e, ue = \(\cfrac12\) ε0e2 . Both u and um are proportional to the square of the appropriate field magnitude.]