Until about 4.6 billion years ago, our solar system was a giant cloud of gas, dust, and ice. As the cloud whirled around, gravity caused it to shrink. The inner part became the Sun. The outer pieces took shape as the planets.
The Sun formed because heat and pressure within the cloud triggered nuclear fusion. Hydrogen atoms were crushed—or fused—together to form helium atoms. Staggering amounts of energy were released. This reaction is the same as what happens when a hydrogen bomb explodes. Intense gravity keeps these ongoing explosions from ripping the Sun apart.