
Fig. 1. Magnetic flux lines around a straight, current-carrying wire. The arrows indicate current flow.
Magnetic fields are produced when the atoms of certain materials align themselves. Iron is the
most common metal that has this property. The atoms of iron in the core of the earth have become aligned to some extent; this is a complex interaction caused by the rotation of our planet and its motion with respect to the magnetic field of the sun. The magnetic field surrounding the earth is responsible for various effects, such as the concentration of charged particles that you see as the aurora borealis just after a solar eruption.
When a wire is coiled up, the resulting magnetic flux takes a shape similar to the flux field surrounding the earth, or the flux field around a bar magnet. Two well-defined magnetic poles develop, as shown in Fig. 2.

Fig. 2. Magnetic flux lines around a current-carrying coil of wire. The flux lines converge at the magnetic poles.