All this begins when a huge cloud of interstellar dust gets concentrated in one region of space and time. Over the period of time gravity pulls the dust of cloud together and form a spinning ball of gas just like Jupiter. When more and more mass is added to the huge ball of spinning gas the mass of the spinning ball rises which eventually rise the temperature in its core.
Gravity push the ball to the centre of the core and reaches a certain point when the temperature is so high that atoms present in the core starts colliding with each other and starts the first fusion reaction.
You all be wondering that how can a single atom release such a huge amount of energy which can fuel up the star which is million times bigger than our own planet. Well that’s basic physic laws. Albert Einstein proved that even if a tiny amount of matter is converted into energy, the energy released will be so huge that it can destroy a whole city altogether in just fraction of second. Everything what I said can be summarized in just a small equation, E=mc^2, where “E” is energy released, “m” is the mass of the matter from whom energy is being extracted and “c” is the speed of light. So, you can see that even if a small amount of matter is converted into pure energy then the energy released if square of the speed of light (speed of light is 299,792,458 m/s).
In short, stars come into existence when huge cluster of interstellar dust is shaped by gravity and ignites a nuclear reaction in the core due to the immense pressure and temperature inside it. Clouds of gas are common in our galaxy and in other galaxies like ours. These clouds are called nebulae. A typical nebula is many light-years across and contains enough mass to make several thousand stars the size of our sun. The majority of the gas in nebulae consists of molecules of hydrogen and helium–but most nebulae also contain atoms of other elements. The core of the cloud collapses faster than the outer parts, and the cloud begins to rotate faster and faster to conserve angular momentum. When the core reaches a temperature of about 2,000 degrees Kelvin, the molecules of hydrogen gas break apart into hydrogen atoms. Eventually the core reaches a temperature of 10,000 degrees Kelvin, and it begins to look like a star when fusion reactions begin. When it has collapsed to about 30 times the size of our sun, it becomes a protostar.
A star balances itself due to two forces acting on it in different direction. Its Gravitational force and fusion reaction inside its core. When two atoms fuses in a core of a star it releases energy and force which push the star outward but the gravity push the star inward maintaining a perfect balance. A star dies when it runs out of fuel and gravity becomes the dominant force there and all the matter gets attracted towards the core and it explodes in a supernova.
Our Sun seems pretty calm when we look at it at the time of sunrise and sunset but have you ever imagined that every second sun releases energy which is equivalent to millions of nuclear bombs exploding. The total energy released by sun in one second is 384.6 septillion watts (3.846×10^26 W). Next time when you are looking at the sun, you are seeing a huge nuclear fusion reactor up in the sky.