The cause of Earth's magnetic field (the surface magnetic field) is not known for certain, but is possibly explained by dynamo theory. The magnetic field extends several tens of thousands of kilometers into space.
The field is approximately a magnetic dipole, with one pole near the geographic north pole and the other near the geographic south pole. An imaginary line joining the magnetic poles would be inclined by approximately 11.3° from the planet's axis of rotation.
The field is similar to that of a bar magnet, but this similarity is superficial. The magnetic field of a bar magnet, or any other type of permanent magnet, is created by the coordinated motions of electrons (negatively charged particles) within iron atoms. The Earth's core, however, is hotter than 1043 K, the temperature at which the orientations of electron orbits within iron become randomized. Such randomization tends to cause the substance to lose its magnetic field. Therefore the Earth's magnetic field is caused not by magnetised iron deposits, but mostly by electric currents (known as telluric currents).
The Earth's magnetic field reverses at intervals, ranging from tens of thousands to hundreds of thousands of years. It is believed that this last occurred some 600,000 years ago (Comins - DEU p.84). The overall geomagnetic field is becoming weaker at a rate which will cause the field to disappear by about 4000 AD.1 Other sources have put the date of field collapse as early as 3000 AD.
Another feature that distinguishes the Earth magnetically from a bar magnet is its magnetosphere. At large distances from the planet, this dominates the surface magnetic field. In addition, the magnetized elements within the planetary core are undergoing rotation and are not static.