
Image: Sun Emits a Solstice CME | Credit: NASA Goddard
Before it was a star
A star is a sphere of gas held together by its own gravity. A star’s life is a constant struggle against the force of gravity. Gravity constantly works to try and cause the star to collapse. The star’s core, however is very hot which creates pressure within the gas. This pressure counteracts the force of gravity, putting the star into what is called hydrostatic equilibrium.
A star is okay as long as the star has this equilibrium between gravity pulling the star inwards and pressure pushing the star outwards.
During most a star’s lifetime, the interior heat and radiation is provided by nuclear reactions in the star’s core.
Video: Sun Emits 3 X-class Flares in 2 Days | Credit: Genna Duberstein, Scott Wiessinger, Karen Fox

Planetary nebula IC 418, the star at the center was a red giant
Image: Hubble’s Spirograph | Credit: NASA Goddard
Gravitational collapse
Sooner or later, though, all stars begin to run out of hydrogen in their cores, and stellar death gets underway. Once a star has exhausted its supply of hydrogen in its core, leaving nothing but helium, the outward force created by fusion starts to decrease and the star can no longer maintain equilibrium. The force of gravity becomes greater than the force from internal pressure and the star begins to collapse. Its inner layers start to collapse, which squishes the core, increasing the pressure and temperature in the core of the star. While the core collapses, the outer layers of material in the star to expand outward. The star expands to larger than it has ever been. At this point the star is called a red giant.
The results of this collapse depend on the mass of the star.