The nebular theory describes the formation of the sun, planets, moons, and asteroids around 4.5 billion years ago from a nebula cloud comprising dust and gas, according to Universe Today. Gravity condensed the gas into dense regions, which grew into clumps of matter. The nebula cloud spread to form a rotating disk that became the plane of the solar system, which is still in evidence because all planets orbit around the sun in the same direction and plane.
Formation of the sun
The least amount of centripetal force was at the center of the rotating disk, so most of the mass from the nebula cloud became attracted to this area due to the force of gravity. Most of the material was hydrogen gas that came under intense pressure, which heated it to a critical point, leading to it fusing with another hydrogen atom, creating helium and giving birth to the sun.
Formation of planets and the moon
The clumps of matter grew in size to form, or early planets, slamming into one another as they orbited the early sun. According to nebular theory, an early form of planet Earth collided with an object, causing debris to fly into space, which then reformed within the Earth's gravitational field to form the moon.