How a star dies depends upon its mass. Moderate stars conserve their energy and eventually puff off their outer layers to form spectacular planetary nebulae. Massive stars, live fast and die young, exploding as violent supernovae.
Low Mass Stars
The Helix Nebula: a Gaseous Envelope Expelled By a Dying Star
NASA, ESA, C.R. O'Dell (Vanderbilt University), M. Meixner and P. McCullough (STScI)
From the red giant stage, a low mass star (less than 8 times the mass of the Sun) will continue to convert helium into carbon and oxygen, inside its core, until the helium runs out. For the second time in its life the nuclear reactions stop and gravity once again takes the upper hand.
The Cat's Eye Nebula: Dying Star Creates Fantasy-like Sculpture of Gas and Dust
NASA, ESA, HEIC, and The Hubble Heritage Team (STScI/AURA)
This time however the star does not have enough mass to re-start any nuclear reactions so the core contracts until the electrons are so tightly bound that they can't be pushed any closer together. The core becomes a white dwarf and is now about the size of the Earth.
As the core contracts, the outer layers of the star lift off forming a ring of gas, known as a planetary nebula, around the collapsing core.
The white dwarf will shine for a few thousand years giving off heat generated when the core contracted. It will eventually cool, radiating away the last of its heat and fading out of sight.
High Mass Stars
Stars that are more than 8 times the mass of the Sun die in a much more spectacular fashion.
Chandra X-ray image of the supernovas remnant Cassiopeia A (Cas A).
Source: Chandra X-ray Observatory, NASA/CXC/SAO/Rutgers/J.Hughes
When the core of a massive star runs out of helium the gravitational collapse of the star's core is able to increase the temperature until carbon and oxygen begin to fuse. Thus the nuclear reactions begin once again. This cycle of contracting, heating and nuclear fusion continues until the core of the star is made of iron.
By this time the nuclear reactions have also spread into the outer regions of the star. The star now has layers where different nuclear reactions are occurring to produce elements such as silicon, sulfur, oxygen, nitrogen, carbon and helium.
The iron core of the star cannot be used in a nuclear fusion reaction. Instead the iron starts to break down and the core undergoes a catastrophic collapse which ends abruptly. The outer layers of the star rebound in a violent explosion called a supernova.
The energy released in the supernova explosion is greater than all the energy produced by the star throughout its entire life. After the explosion new elements are scattered into space, ready to become available in the formation of new stars.
From the explosion only the stellar core remains. If the stellar core was small (less than 3 times the mass of the Sun) the collapse forms a neutron star. These stars are about 10 km across, are incredibly dense (a teaspoon of a neutron star weighs the same as 200 million elephants) and have very strong magnetic fields.
A special type of neutron star is the pulsar. Pulsars emit beams of radio waves from their magnetic poles. As the pulsar spins, the radio beams pass by the Earth in flashes or pulses, similar to the beam of a lighthouse.
If the stellar core is greater than 3 times the mass of the Sun, the catastrophic collapse continues unheeded. The entire mass of the core shrinks to a point (or singularity) forming a black hole. The gravitational pull of a black hole is so great that not even light can escape.