Approximately 4.6 billion years ago, the solar system was a cloud of dust and gas known as a solar nebula. Gravity collapsed the material in on itself as it began to spin, forming the sun in the center of the nebula.
With the rise of the sun, the remaining material began to clump up. Small particles drew together, bound by the force of gravity, into larger particles. The solar wind swept away lighter elements, such as hydrogen and helium, from the closer regions, leaving only heavy, rocky materials to create smaller terrestrial worlds like Earth. But farther away, the solar winds had less impact on lighter elements, allowing them to coalesce into gas giants. In this way, asteroids, comets, planets, and moons were created.
Earth's rocky core formed first, with heavy elements colliding and binding together. Dense material sank to the center, while the lighter pieces created the crust. The planet's magnetic field probably formed around this time. Gravity captured some of the lighter elements that make up the planet's early atmosphere.
Early in its evolution, Earth suffered an impact by a large body that catapulted pieces of the young planet's mantle into space. Gravity caused many of these pieces to draw together and form the moon, which took up orbit around its creator.
The flow of the mantle beneath the crust causes plate tectonics, the movement of the large plates of rock on the surface of the Earth. collisions and friction gave rise to mountains and volcanoes, which began to spew gases into the atmosphere.
Although the population of comets and asteroids passing through the inner solar system is sparse today, they were more abundant when the planets and sun were young. Collisions from these icy bodies likely deposited much of the Earth's water on its surface. Because the planet is in the Goldilocks zone, the region where liquid water neither freezes nor evaporates bur can remain as a liquid, the water remained at the surface, which many feel plays a key role in the development of life.