The field really isn't quite zero outside the solenoid. If you picture the field lines running one way inside the solenoid, you know that they have to loop back outside the solenoid, because magnetc field lines always form loops. (There are no known isolated magnetic charges where lines would start and stop, unlike electric charges.) However, if the solenoid is much longer than it is wide, those outside returning lines spread out over a much bigger area than the lines inside the solenoid. Lower line density means the same as lower magnetic field, so the field outside is much weaker than the field inside. Of course if the solenoid is short and squat, this argument doesn't work and the field outside is not especially weak.
Mike W.If your solenoid is very very much longer than it is wide, then from far away it looks more or less like a straight wire, and the magnetic field around a straight wire loops in the plane perpendicular to the wire. Both effects contribute in general, so not only does the magnetic field outside a solenoid have to loop back to the beginning, it also has a bit of a twist to it. These fields are usually called "fringe fields" by people who care about them. You can try to contain the fringe fields either by wrapping your solenoid around in a torus (Google "Rowland's Ring" for some pictures), or to arrange a magnetically permeable material to go through the core of your solenoid and return around the outside, as most transformers are constructed.
(published on 08/07/06)