Our solar system is part of an entity called our universe. There were many attempts made in the past to explain how our solar system and universe came into existence as we observe it today. Most scientists use the Big Bang Theory, though some people have other theories.
This theory is based around the idea that an enormous explosion occured about 13.7 billion years ago. That is about 13,700,000,000 years ago. This is three times the age of Earth! The Big Bang was not a usual explosion in space because space and time themselves were made in the explosion. This explosion caused the formation of the matter and energy in the universe. At first, the universe was very hot. The planets, stars and all other heavenly bodies formed starting some time after the Big Bang after the universe had cooled down.
The universe had been expanding and cooling since the Big Bang. Most galaxies are moving further away from our Milky Way galaxy. The exceptions are the few galaxies that are close enough to the Milky Way for gravity to overcome the universe's expansion.
Scientists can still see the faint light from when the universe was hot. Over time, the universe's expansion stretched out the light, turning it into weak microwave light. Scientists can detect this microwave light.
The solar system formed out of a big cloud of gas and dust about 4.6 billion years ago.
Stars and solar systems that are very similar to the Sun are now forming in the Eagle Nebula (also known as M16). While this is not a picture of our own sun, it can give you an idea of what our solar system looked like billions of years ago. These gas clouds that you see in this image were formed from earlier stars that exploded and left stuff behind.
Small finger-like parts of these clouds, especially at the "top" of the first column on the left, are the new stars that are forming. Astronomers who have been watching these stars form have seen changes happen in just a few years, which is a very rapid change for the life of a star.