After the sun spun to light, the planets of the solar system began to form. But it took another hundred million years for Earth's moon to spring into existence. There are three theories as to how our planet's satellite could have been created: the giant impact hypothesis, the co-formation theory and the capture theory.
Giant impact hypothesis
This is the prevailing theory supported by the scientific community. Like the other planets, the Earth formed from the leftover cloud of dust and gas orbiting the young sun. The early solar system was a violent place, and a number of bodies were created that never made it to full planetary status. According to the giant impact hypothesis, one of these crashed into Earth not long after the young planet was created.
Known as Theia, the Mars-size body collided with Earth, throwing vaporized chunks of the young planet's crust into space. Gravity bound the ejected particles together, creating a moon that is the largest in the solar system in relation to its host planet. This sort of formation would explain why the moon is made up predominantly of lighter elements, making it less dense than Earth — the material that formed it came from the crust, while leaving the planet's rocky core untouched. As the material drew together around what was left of Theia's core, it would have centered near Earth's ecliptic plane, the path the sun travels through the sky, which is where the moon orbits today.
Moons can also form at the same time as their parent planet. Under such an explanation, gravity would have caused material in the early solar system to draw together at the same time as gravity bound particles together to form Earth. Such a moon would have a very similar composition to the planet, and would explain the moon's present location. However, although Earth and the moon share much of the same material, the moon is much less dense than our planet, which would likely not be the case if both started with the same heavy elements at their core.
Perhaps Earth's gravity snagged a passing body, as happened with other moons in the solar system, such as the Martian moons of Phobos and Deimos. Under the capture theory, a rocky body formed elsewhere in the solar system could have been drawn into orbit around the Earth. The capture theory would explain the differences in the composition of the Earth and its moon. However, such orbiters are often oddly shaped, rather than being spherical bodies like the moon. Their paths don't tend to line up with the ecliptic of their parent planet, also unlike the moon.
Although the co-formation theory and the capture theory both explain some elements of the existence of the moon, they leave many questions unanswered. At present, the giant impact hypothesis seems to cover many of these questions, making it the best model to fit the scientific evidence for how the moon was created.