The Earth is nearly spherical, having a diameter of 7,928 miles (12,756 km) at the equator but only 7,902 miles (12,714 km) from pole to pole. The slight broadening at the equator is the result of centrifugal forces from the Earth's spin, and originally set in when the planet was molten. The Earth is the densest planet in the solar system, with an average density 5.5 times that of water. When the Earth condensed from the primal dustcloud the chemical elements and compounds that formed it separated into layers: the denser materials sank to the centre of the Earth and the lighter ones floated to the top, much as a layer of light oil floats on denser water.
In 1952 the American geophysicist Francis Birch set out a description of the general structure of our planet which has been modified in only minor ways since. The inside of the Earth is hot, but the pressure there is also very high: the most extreme conditions occur at the centre where the temperature is about 6,000°C and the pressure is 3 million times atmospheric pressure. Heat tends to make rocks and metals melt, but pressure tends to solidify them, so it is the combination of these two conflicting factors that determines whether the materials are liquid or solid. The centre of the Earth is a rather lumpy spherical core, mainly made of iron, with a radius of roughly 2,220 miles (3,500 km). The innermost regions of the core, out to a radius of 600 miles (1000 km), are solid, but a thick outer layer is molten. The very top layers of the Earth form a thin skin, the crust, which is only a few miles thick. Between crust and core lies the mantle, which is solid, formed from a variety of silicate rocks. The mantle also divides into an inner layer and an outer layer, with the division occurring at a radius of about 3,600 miles (5,800 km). Above this 'transition zone' the main rocks are olivine, pyroxine, and garnet; below it their crystal structures become more tightly packed, forming such minerals as perovskite. The outermost parts of the mantle, and the deeper parts of the crust where the two join, are again molten.
The crust is between 3 and 12 miles (5 and 20 km) thick, and there's a lot going on there. Those parts of the crust that form the continental land masses are mainly made of granite. Beneath the oceans, the crustal layer is predominately basalt, and this basalt layer continues underneath the continental granite. So the continents are broad, thin sheets of granite stuck on top of a basalt skin. From the Earth's surface the most evident features of the granite layers are mountains. The highest ones look big to us, but they rise no more than 5 miles (9 km) above sea level, a mere seventh of a per cent of the Earth's radius. The deepest part of the ocean, the Mariana Trench in the northwest Pacific, plunges 7 miles (11 km) beneath the waves. The overall deviation from an ideal sphere (strictly, spheroid, because of the flattening of the poles) is about one-third of a per cent, about as irregular as the shallow indentations you find on a basketball, which add to its grip. Our home planet, give or take a bit of squashing, is remarkably round and surprisingly smooth. Gravity made it that way, and it keeps it that way, except that some small but interesting movements in the mantle and the crust add a few wrinkles.
How do we know all this? Mainly because of earthquakes. When an earthquake hits, the whole Earth rings like a bell hit by a hammer. Shockwaves, vibrations emitted by the earthquake, travel through the Earth. They are deflected by transition zones between different kinds of material, such as that between core and mantle, or lower and upper mantle. They bounce off the Earth's crust and head back down again. There are several kinds of wave, and they travel with different speeds. So the short sharp shock of an earthquake gives rise to a very complex pattern of waves. When the waves hit the surface they can be detected and recorded, and recordings made in different places can be compared. Working backwards from these recorded signals, it is possible to deduce a certain amount about the underground geography of our planet.
One consequence of the Earth's internal structure is a magnetic field. A compass needle points roughly north. The standard 'lie-to-children' is that the Earth is a giant magnet. Let's unpack the next layer of explanation.
The Earth's magnetic field has long been something of a puzzle since magnets are seldom made out of rock, but once you realize that the Earth has a whopping great lump of iron inside it, everything makes much more sense. The iron doesn't form a 'permanent' magnet, like the ones you inexplicably buy to stick plastic pigs and teddy bears on the fridge door; it's more like a dynamo. In fact it's called the geomagnetic dynamo. The iron in the core is, as we've said, mostly molten, except for a slightly lumpy solid bit in the middle. The liquid part is still heating up, the old explanation of this was that radioactive elements are denser than most of the rest of the Earth, and therefore sank to the middle where they became trapped, and their radioactive energy is showing up as heat. The current theory is quite different: the molten part of the core is heating up because the solid part is cooling down. The liquid iron that is in contact with the solid core is itself slowly solidifying, and when it does so it loses heat. That heat has to go somewhere, and it can't just waft away unnoticed as warm air because everything is thousands of miles underground. So it goes into the molten part of the core and heats it up.
You're probably wondering how the part that is in contact with the solid core can simultaneously be getting cooler, so that it solidifies too, and be getting hotter as a result of that solidification, but what happens is that the hot iron moves away as soon as it's been warmed up. For an analogy, think about a hot air balloon. When you heat air, it rises: the reason is that air expands when it gets hot, so becomes less dense, and less dense things float on top of denser things. A balloon traps the hot air in a huge cloth bag, usually brightly coloured and emblazoned with adverts for banks and estate agents, and floats up along with the air. Now hot iron rises, just as hot air does, and that takes the newly heated iron away from the solid core. It heads upwards, cooling slowly as it does so, and when it gets to the top it cools down, comparatively speaking, and starts to sink again. The result is that the Earth's core circulates up and down, being heated at the bottom and cooling at the top. It can't all go up at the same time, so in some regions it's heading up, and in others it's heading back down again. This kind of heat-driven circulation is called convection.
According to physicists, a moving fluid can develop a magnetic field provided three conditions hold. First, the fluid must be able to conduct electricity, which iron can do fine. Secondly, there has to be at least a tiny magnetic field present to begin with, and there are good reasons to suppose that the Earth had a bit of personal magnetism, even early on. Thirdly, something has to twist the fluid, distorting that initial magnetic field, and for the Earth this twisting happens by way of Coriolis forces, which are like centrifugal forces but a bit more subtle, caused by the Earth's rotation on its axis. Roughly speaking, the twisting tangles the original, weak magnetic field like spaghetti being twirled on to a fork; then the magnetism bubbles upwards, trapped in the rising parts of the iron core. As a result of these motions, the magnetic field becomes a lot stronger.
So, yes, the Earth does behave a bit as though it had a huge bar magnet buried inside it, but there's rather more going on than that. Just to paint the picture in a little more detail, there are at least seven other factors that contribute to the Earth's magnetic field. Some of the materials of the Earth's crust can form permanent magnets. Like a compass needle pointing north, these materials align themselves with the stronger field from the geomagnetic dynamo and reinforce it. In the upper regions of the atmosphere is a layer of ionized gas, gas bearing an electrical charge. Until satellites were invented, this 'ionosphere' was crucial for radio communications, because radio waves bounced back down off the charged gas instead of beaming off into space. The ionosphere is moving, and moving electricity creates a magnetic field. About 15,000 miles (24,000 km) out lies the ring current, a low-density region of ionized particles forming a huge torus. This slightly reduces the strength of the magnetic field. The next two factors, the magnetopause and the magnetotail, are created by the interaction of the Earth's magnetic field with the solar wind, a continual stream of particles outward bound from our hyperactive sun. The magnetopause is the 'bow wave' of the Earth's magnetic field as it heads into the solar wind; the magnetotail is the 'wake' on the far side of the Earth, where the Earth's own field streams outwards getting ever more broken up by the solar wind. The solar wind also causes drag along the direction of the Earth's orbit, creating a further kind of motion of magnetic field lines known as field-aligned currents. Finally, there are the convective electrojets. The 'northern lights', or aurora borealis, are dramatic, eerie sheets of pale light that waft and shimmer in the northern polar skies: there is a similar display, the aurora australis, near the south pole. The auroras are generated by two sheets of electrical current that flow from magnetopause to magnetotail; these in turn create magnetic fields, the westward and eastward electrojets.