# Why is the magnetic flux at the end of a solenoid half of that in the interior?

While doing a problem I didn't understand why is the the magnetic flux and the end of a long solenoid is:

$$\phi = \frac{\mu inS}{2}$$

Where $\mu$ is the permeability of free space, $n$ is the number of turns, $i$ is the current, and $S$ is the area of cross section.

In the solution , it is given that the That the field at the end is:

$$B= \mu ni/2$$

Hence the flux is $BS$.

But isn't the field non uniform at the end and isn't $\mu nI/2$ the field along the axis only ?

Also , how come the flux at the end not equal to the flux somewhere deep in the solenoid ?

Which should be $\phi = \mu niS$

Since the same field lines are passing through the middle and the end ?