The magnetic field \( B \) at a point on the axis of a bar magnet is given by the formula:
\[
B = \frac{\mu_0 M}{2 \pi x^3}
\]
where:
- \( \mu_0 \) is the permeability of free space,
- \( M \) is the magnetic moment of the bar magnet,
- \( x \) is the distance from the center of the magnet.
Thus, the magnetic field is directly proportional to the magnetic moment and inversely proportional to the cube of the distance from the magnet.