When a star runs out of hydrogen, it starts to fuse helium atoms together.
This process releases less energy than the fusion of hydrogen atoms, so the star starts to cool down.
The cooler temperature means that the friction between the matter and the space fabric inside the star decreases. This causes the star to collapse under its own gravity.
The collapse of the star causes the core to heat up again, and the fusion of helium atoms starts to produce more energy. This causes the star to expand and become a red giant.
Eventually, the star runs out of helium and starts to fuse carbon atoms together. This process releases even less energy than the fusion of helium atoms, so the star cools down even more.
The cooler temperature causes the star to collapse even more, and the core becomes very dense. This causes the core to become unstable and collapse in a supernova explosion.
The supernova explosion scatters the star’s matter into space, and some of this matter can be used to form new stars and planets.