The solar system formed over 4.6 billion years ago from a dense cloud of gas and dust that collapsed under its own gravity. As the central mass condensed to form the sun, the surrounding matter began to clump together through collisions to create the planets. The planets follow elliptical orbits around the sun, trapped by its strong gravitational pull along with other celestial bodies like asteroids, comets and moons. Our solar system resides within the Milky Way galaxy.