As a star comes towards the end of its life it begins to expand as the energy released increases the outward pressure of the plasma causing it to become a red giant. This star then goes through a series of expansions and compressions shedding layers rich in carbon in nitrogen as it goes. More massive stars have a more impressive ending, their death throes come in the form of a super nova where their shells are exploded off often leaving nothing but an incredibly dense neutron star.
Images: NASA/ESA/ESO