After Oersted discovered that electric currents produce a magnetic field and Ampere discovered that electric currents attracted and repelled each other similar to magnets, it was natural to hypothesize that all magnetic fields are due to electric current loops. In this model developed by Ampere, the elementary magnetic dipole that makes up all magnets is a sufficiently small Amperian loop of current I. The dipole moment of this loop is m = I A where A is the area of the loop.
These magnetic dipoles produce a magnetic B field. One important property of the B-field produced this way is that magnetic B field lines neither start nor end (mathematically, B is a solenoidal vector field); a field line either extends to infinity or wraps around to form a closed curve. To date no exception to this rule has been found. (See magnetic monopole below.) Magnetic field lines exit a magnet near its north pole and enter near its south pole, but inside the magnet B-field lines continue through the magnet from the south pole back to the north.[nb 9] If a B-field line enters a magnet somewhere it has to leave somewhere else; it is not allowed to have an end point. Magnetic poles, therefore, always come in N and S pairs.
More formally, since all the magnetic field lines that enter any given region must also leave that region, subtracting the 'number'[nb 10] of field lines that enter the region from the number that exit gives identically zero. Mathematically this is equivalent to:
where the integral is a surface integral over the closed surface S (a closed surface is one that completely surrounds a region with no holes to let any field lines escape). Since dA points outward, the dot product in the integral is positive for B-field pointing out and negative for B-field pointing in.
There is also a corresponding differential form of this equation covered in Maxwell's equations below.