Stars and planets are formed from huge clouds of dust and hydrogen. Gravity pulls them close together.
Red Giant v Supergiant
Low mass stars like the sun are formed when all this pulling of gases and dust from gravity creates heat in the central core. Nuclear fusion takes place at these high temperatures and hydrogen forms a helium nucleus which generates energy.
Planetary Nebula v Supernova
Low mass stars use up their hydrogen very slowly and therefore have long lives as the hydrogen fuels the star. High mass stars use their hydrogen quickly and have short lives.
White Dwarf v Neutron star or black hole
Once all the hydrogen is used up no energy is produced and gravity causes the core to collapse and release heat. This heat causes nuclear fusion around the outside and therefore releases lots of energy and heat making it a red giant. supergiants are the same but on a bigger scale.
In low mass stars, a planetary nebula is formed when a red giant ejects its outer atmosphere. In high mass stars the great mass causes the core to collapse and therefore an explosion called a supernova.
After a planetary nebula only the core remains which is a hot white dwarf planet. After a supernova, the core becomes unstable and gravity collapses in on itself creating a black hole. Or when the core collapses the high pressures squeeze protons and electrons resulting in a neutron star.