Let ‘r’ be radius of solenoid of length 2l.

To calculate magnetic field at a point on axis of solenoid, consider a small element of thickness ‘dx’ of solenoid at a distance ‘x’ from ‘o’.
Number of turns in this element = n.dx
If current ‘i’ flows through element ‘ndx’ the magnitude of magnetic field at P due to this element is

If point 'p' is at large distance from 'o' i.e r >> l and r >> a then [(r - x)2 + a2] = r2

This equation gives the magnitude of magnetic field at a point on axis of a solenoid.
This equation is similar to the expression for magnetic field on axis of a short bar magnet. Hence a solenoid carrying current behaves as a bar magnet.