The solar system, which includes the Sun and all the planets which orbit it, originated approximately 4.6 billion years ago. This figure was derived from radiocarbon dating of meteorites, such as the Canyon Diablo meteorite, which is approximately 4.6 billion years old.
Scientists believe the Sun and the rest of the solar system were formed at about the same time, when a giant molecular cloud — which would have been several light years across — gravitationally collapsed into a condensed mass, forming several stars besides our Sun. This is called the nebular theory, and while not perfect, it does explain most of the current structure of our solar system.
When densities within the collapsing cloud reached a certain extreme level, nuclear fusion would have been initiated, and the Sun was born. Orbiting the Sun would be a debris disc which eventually condensed into spheres which make up the planets. Also called a protoplanetary disc, several of these have been observed in far-away nebulae within our Galaxy. The densest portion of these discs are areas called Bok globules, where stars are believed to be born. The actual process of star birth is hidden from our telescopes due to the opaque dust which surrounds it.
Planets formed via accretion, where dust-sized chunks of matter orbiting the early Sun accreted into planetesimals and finally full-fledged planets. This process of accretion would have taken at least 30 million years, perhaps longer. The Earth itself was formed about 4.57 billion years ago, about 30 million years after the origin of the solar system.
Closer to the Sun, the temperature was too high for volatiles like water and methane to condense, so small rocky planets — made of iron and silicates — formed here. Today, these make up the inner solar system, and include Mercury, Venus, Earth, and Mars. Farther away from the Sun, the temperature was low enough for volatiles to condense, and the large gas giants formed. One gas giant, Jupiter, it so large that its gravitational influence keeps breaking up the rocks located between its orbit and that of Mars, creating the asteroid belt. These gas giants make up the outer solar system. Beyond the outer system is another asteroid belt, the Kuiper belt, and beyond that, interstellar space.