This is a derivation of the magnetic flux density around a solenoid that is long enough so that fringe effects can be ignored. In Figure 1, we immediately know that the flux density vector points in the positive z direction inside the solenoid, and in the negative z direction outside the solenoid.