The solar system formed from a cloud of gas and dust approximately 4.6 billion years ago. As the cloud collapsed due to gravity, it began to spin and form a disk. Most of the material ended up in the center to form the sun, while the rest flattened into a protoplanetary disk that later condensed into planets, moons, and other objects like asteroids and comets. Over time, gravitational interactions between the objects led them to take on orbits within separate regions like the inner and outer planets, asteroid and Kuiper belts, and scattered disk.