Here's how it happens:
* Main Sequence: Stars spend most of their lives in the main sequence, fusing hydrogen into helium in their cores.
* Red Giant: When a star runs out of hydrogen fuel, it starts fusing helium, causing it to expand into a red giant.
* Planetary Nebula: As the red giant sheds its outer layers, it creates a planetary nebula.
* White Dwarf: The remaining core of the star, consisting mostly of carbon and oxygen, contracts into a dense, hot white dwarf.
White dwarfs are incredibly dense, packing the mass of our Sun into a volume roughly the size of Earth. They have no ongoing fusion and are slowly cooling down, eventually fading into black dwarfs.