We'll assume you are talking about a solenoidal electromagnet made
up of many turns of conducting wire (say, copper) wound around a
cylinder with a length that is much longer than the diameter.
The magnetic field at any point in space can be computed by
summing over the magnetic fields produced by each turn of wire in your
solenoid. It turns out that for an infinitely long solenoid, with the
same number of turns per unit length of the solenoid, the magnetic
field is constant in strength everywhere inside. If your solenoid has
ends, then you can think of it as an infinitely long solenoid minus the
end parts that stretch off to infinity. The magnetic field strength on
the axis going right through the solenoid, in the place on the end of
the solenoid is then the field of an infinitely long solenoid minus
half of it because half is missing, and so the field strength is half
as big on the ends (but right in the middle).
The field strength in the middle of a long solenoid is almost
exactly that of an infinitely long solenoid, or twice that on the ends.
The field lines really have to go around in loops because they
cannot begin or end anywhere (there are no magnetic charges). Field
lines penetrate through the coils and the field starts pointing out
from the ends of the solenoid and turning around to go back in the
other end of the solenoid. We often call this field the "fringe field"
of the solenoid.
You can modify the field shape by wrapping your solenoid around an
iron core, and if the iron core loops back around to go back in the
other end of the solenoid, the fringe field can be reduced. Iron has a
large magnetic permeability, and magnetic field lines prefer to stay
inside the iron. So the magnetic field strength in this case would
almost be the same on the ends of the solenoid as in the center.
If the solenoid is made out of a superconducting sheet, or tightly
wrapped superconducting wire, then the field strength will also be the
same or nearly so at the ends as in the middle. The reason for this is
that a superconductor expels magnetic fields from its bulk, so magnetic
field lines cannot stray through the coils and "leak" out the sides.
Magnetic flux is the surface integral of the magnetic field over an
area. If the magnetic field has a lower strength, then the magnetic
flux will be less as well.
(republished on 08/02/06)