A star will die when all the hydrogen gas in its core is used up in nuclear reactions. The lifespan of a star is determined by the original mass of the star. A star with a big mass has a shorter life span compared to a star with a small mass. For example, stars that are 50 times bigger than the Sun live for only a few million years. Stars that are smaller than the Sun can live more than 10 billion years. A died star with become either a white dwarf , a black dwarf , a neutron star or black hole , depending on its size as shown in the figure below.
Large and super giant stars explode with great explosion called supernova before transforming into neutron star and black hole respectively.
Medium sized stars change to white dwarfs or black dwarfs without exploding off outer layers.
They only form planetary nebulae, which are huge shells of gas ejected near the ends of their life time.