A magnet free to rotate in a uniform magnetic field \(\vec B\) aligns its dipole moment \(\vec M\) with \(\vec B\).
Work must be done to rotate the magnet from this equilibrium position. The work done is stored as the magnetic potential energy, also called its orientation energy. In a finite angular displacement from 0 to θ, the magnetic potential energy

1. When θ = 0°, cos θ = cos 0° = 1, Uθ = – MB. At this position, the magnetic moment of the bar magnet is lined up with the field and its magnetic potential energy is minimum. This is its most stable equilibrium position.
2. When θ = 180°, cos θ = cos 180° = – 1, Uθ = MB. At this position, the magnetic moment is antiparallel to the field and its magnetic potential energy is maximum. This is its most unstable position.
3. When θ = 90°, cos θ = cos 90° = 0, Uθ = 0. At this position, the bar magnet is perpendicular to the magnetic field. Its magnetic potential energy is zero.