The solar system formed from a giant cloud of dust and gas called a nebula approximately 5 billion years ago. As the nebula collapsed due to gravity, the densest parts compressed at its center to form the proto-Sun, while the remaining material flattened into a disk that would eventually form the planets. Over millions of years, dust particles in the disk collided and stuck together, growing into ever larger bodies including planets that began to orbit the newborn Sun. The inner terrestrial planets closest to the Sun include Mercury, Venus, Earth, and Mars, while the outer gas giants are Jupiter, Saturn, Uranus, and Neptune. In a few billion years, the Sun will grow hotter and expand, likely consuming the inner planets