Most of the electrons in an atom exist in pairs that spin in opposite directions, so the magnetic effect of one electron in a pair cancels out the effect of its partner. But if an atom has some unpaired electrons (iron atoms have four), these produce net magnetic fields that line up with one another and turn the whole atom into a mini magnet. When you put a paramagnetic material such as iron in a magnetic field, the electrons change their motion to produce a magnetic field that lines up with the field outside. You have just produced a permanent magnet.
We now know that Earth is magnetic because it's packed with molten rocks rich in magnetic materials such as iron. Just like a bar magnet, Earth's magnetic field stretches out into space, in a region called the magnetosphere, and can affect things around it. When energetic particles zooming in from the Sun (the so-called solar wind) interact with Earth's magnetic field, we get amazing auroras in the sky, the northern lights or aurora borealis, and the southern lights or aurora australis.
Iron is the king of magnetic materials—the metal we all think of when we think of magnets. Most other common metals (such as copper, gold, silver, and aluminum) are, at first sight, nonmagnetic and most non metals (including paper, wood, plastic, concrete, glass, and textiles such as cotton and wool) are nonmagnetic too.
But iron is not the only magnetic metal. Nickel, cobalt, and elements that belong to a part of the Periodic Table (the orderly arrangement chemists use to describe all the known chemical elements) known as the rare-Earth metals (notably samarium and neodymium) also make good magnets.
Some of the best magnets are alloys (mixtures) of these elements with one another and with other elements. Ferrites (compounds made of iron, oxygen, and other elements) also make superb magnets. Lodestone (which is also called magnetite) is an example of a ferrite that's commonly found inside Earth (it has the chemical formula FeO·Fe2O3).
Magnetism is the other side of electromagnetism. If one takes a coil of wire (lots of them) and rotates it (them) in a magnetic field one produces electricity. If one takes a coil of wire (lots of them) in a magnetic field and applies electricity, one produces rotation. The two sides of the same coin..