Magnetic fields surround electric currents, so we surmise that circulating electric currents in the Earth's molten metallic core are the origin of the magnetic field. A current loop gives a field similar to that of the earth. The magnetic field magnitude measured at the surface of the Earth is about half a Gauss and dips toward the Earth in the northern hemisphere. The magnitude varies over the surface of the Earth in the range 0.3 to 0.6 Gauss.
The Earth's magnetic field is attributed to a dynamo effect of circulating electric current, but it is not constant in direction. Rock specimens of different age in similar locations have different directions of permanent magnetization. Evidence for 171 magnetic field reversals during the past 71 million years has been reported.
Although the details of the dynamo effect are not known in detail, the rotation of the Earth plays a part in generating the currents which are presumed to be the source of the magnetic field. Mariner 2 found that Venus does not have such a magnetic field although its core iron content must be similar to that of the Earth. Venus's rotation period of 243 Earth days is just too slow to produce the dynamo effect.