Medium stars expand, as they grow old. Their core starts to run out of hydrogen and helium. Then the outer layer expands, cools, and it becomes less bright and it becomes a red giant. Now that the star is a red giant, the outer core of the star continues to expand. The helium in the core fuses together and form carbon atoms, which then release energy. Then the outer layers of the star start to drift away and form a planetary nebula.
The nebula starts to cool and shrink in size. Now the star becomes a white dwarf. It is a stable star with no nuclear fuel. The white dwarf radiates its leftover heat for billions of years until it all it has been used. Now it will become a black dwarf (A cold, dark dead star).