The energy density \( u \), which is the energy stored per unit volume in a magnetic field of strength \( B \), is given by the formula:
\[
u = \frac{B^2}{2 \mu_0},
\]
where \( \mu_0 \) is the permeability of free space.
This expression shows that the energy stored in the magnetic field increases with the square of the magnetic field strength, and it quantifies how much magnetic energy is contained within a given volume.