Earth's core is primarily composed of iron. The inner core is a solid ball which takes up around 20% of the total radius of the Earth, made of solid iron. Even though it is hot, large amounts of pressure keep it in a solid state. The outer core is also made of iron, with some nickel. Unlike the inner core, the outer core is under less pressure. As such, it is a liquid and movement of this layer produces a magnetic field which goes all the way up to the surface and out through the crust.
Cross section of the varying layers of the Earth. Credit: NASA (Adapted from Goddard Media Studios).
Magnetic field of Earth. Credit: Peter Reid, The University of Edinburgh
This magnetic field looks very similar to the field seen when a dipole magnet is put in some iron filings. The magnetic field comes out of the geographic south pole (magnetic north pole), and goes into the geographic north pole (magnetic south pole). We call this magnetic field the geomagnetic field. The magnetic poles continually move, due to the nature of the movement in the outer core producing the magnetic field. The geomagnetic north pole (magnetic south) is located on Ellesmere Island, Nunavut, Canada, at the time of writing.
Earth's magnetosphere is the region of space around Earth where the magnetic field that dominates the plasma in it, is controlled by Earth. The magnetosphere is shaped by the interaction of the solar wind with the magnetic field of the Earth. The combination of the magnetic field itself and our atmosphere protects Earth from the high energy particles and radiation from the Sun and solar wind.
Without the solar wind, Earth's magnetosphere would look very similar to a bar magnet, with a symmetrical pattern of field lines coming out of the south (geographic) pole and into the north pole. However, pressure of the solar wind coming from the Sun squashes the dayside magnetosphere to be within 70,000 kilometers of the Earth's surface. The opposite occurs on the nightside, where the magnetic field streams behind Earth in a tail-like structure, the magnetotail.
Earth's Magnetosphere. Credit: NASA/Goddard/Aaron Kaase
The Earth's magnetosphere, and the solar wind magnetic field, are separated by a layer called the magnetopause. The magnetopause is between 10 and 20 kilometers thick, and changes position depending on the density and velocity of the solar wind, which buffets the dayside magnetosphere. The magnetopause, dayside magnetosphere, and nightside magnetosphere are often compared to a wind-sock, where the wind causing the wind-sock to flap around is the solar wind. Further upstream in the solar wind ahead of the magnetopause is the bow shock. Similar to the bow wave of a boat, the bow shock is formed as the solar wind abruptly slows down as it approaches the obstacle that is Earth's magnetic field.
The solar wind, being a supersonic flowing plasma, slows down to sub-sonic speeds via a shock wave - similar to the sound shock waves heard when an airplane exceeds the speed of sound in the air. Between the bow shock and the magnetopause is the magnetosheath, where the shocked solar wind, which is now hot and slow, gathers to move around the Earth's magnetic field. Thus the magnetosphere is deflecting much of the harmful solar wind particles to flow around the Earth, rather than collide with the Earth's surface and living beings upon it.
The magnetosphere is not a completely isolated bubble in space. There are many ways for solar wind particles to enter the magnetosphere, and for the solar wind magnetic field to interact with Earth's magnetic field. A phenomena called magnetic reconnection occurs, this is where magnetic field lines which are oppositely directed can be pushed together and the field disconnects, reorients, and reconnects to the opposing field line. This causes the magnetic field to realign and be sent at some speed away from the place it reconnected. This happens primarily in two places in the magnetosphere of Earth: at the tip of the dayside, and inside the center of the tail. This can only happen effectively if the magnetic field in the solar wind is directed oppositely to the magnetic field of the Earth (which goes from south to north). Hence, when the solar wind magnetic field is pointing 'southward', or from north to south, the field lines are opposed and this reconnection can occur.
The field lines now have one end anchored to the Earth, and the other is in the solar wind (ultimately anchored in the Sun). We call this field line an open field line. The solar wind is still moving, and as it moves it now drags the end which is anchored on Earth over the polar cap and the field ends up in the tail region. As more and more field lines are dragged over the pole, a pressure is exerted towards the center of the tail, where field lines are building up. As these field lines are also oppositely directed, they too reconnect once again; however, this time one side is now a closed field line, where both ends are anchored on Earth, and the other is now connected to the solar wind at both ends and continues to travel down tail until it is back in the solar wind. The closed field line is now pushed by pressure gradients back around to the front where it can start the process all over again. This cycle of magnetic field movement is called the Dungey cycle.
Schematic of the Dungey Cycle viewing the Earth from the side. From the paper by Hughes, 1995.
The plasma in the ionosphere likes to stick to the magnetic field as it moves in the Dungey cycle over the polar cap, meaning that we have an ionospheric circulation pattern which corresponds to this. This in one of the things that SuperDARN can see with its multiple radars!