A magnetic field indicates the presence of an electric current, whether it is electricity running through a wire or electrons moving around atomic nuclei. The magnetic field generated by an electric current encircles it perpendicular to the direction of the current.
In permanent magnets, magnetic fields are produced by electrons moving through the magnets in coordinated loops, producing enough of a consistent electric current. Any magnetic field is polar, with a north and south pole where the fields intersect with the magnetic object. Opposite poles attract, while matching poles repel each other.
The magnetic forces between two magnets depends both on the strength of the magnets and the distance between them. When two magnets are brought together with matching poles toward each other, the magnetic field not only pushes them apart, but also applies a twisting force to align them so opposite poles face each other. This is the mechanism used to drive electric motors, although this also uses electromagnets.
Only ferromagnetic materials such as iron and nickel form permanent magnets, but an electric current passing through any material, such as copper, produces a magnetic field. When an electrified copper wire is wrapped around an iron rod, it concentrates the magnetic field inside and creates an effect very similar to a permanent magnet.