If we assume the solenoid to be long, then we can assume the magnetic field inside to be uniform. We can apply Ampere's Law to the loop

(1)

If there areturns of wire per metre of the solenoid them the loopwill encloseturns of wire, each carrying a current I, so will enclose a total current ofThe right hand side of (1) is then

As for the left hand side, outside the coil the magnetic field is zero so this part of the path contributes nothing to the integral. Inside the coil, the magnetic field is a uniformso for the coil of lengththe left hand integral is

Hence

cancels from both sides to give