Several billion years after its life starts, a star will die. How the star dies, however, depends on what type of star it is.
Stars Like the Sun
When the core runs out of hydrogen fuel, it will contract under the weight of gravity. However, some hydrogen fusion will occur in the upper layers. As the core contracts, it heats up. This heats the upper layers, causing them to expand. As the outer layers expand, the radius of the star will increase and it will become a red giant. The radius of the red giant sun will be just beyond Earth's orbit. At some point after this, the core will become hot enough to cause the helium to fuse into carbon. When the helium fuel runs out, the core will expand and cool. The upper layers will expand and eject material that will collect around the dying star to form a planetary nebula. Finally, the core will cool into a white dwarf and then eventually into a black dwarf. This entire process will take a few billion years.
Stars More Massive Than the Sun
When the core runs out of hydrogen, these stars fuse helium into carbon just like the sun. However, after the helium is gone, their mass is enough to fuse carbon into heavier elements such as oxygen, neon, silicon, magnesium, sulfur and iron. Once the core has turned to iron, it can burn no longer. The star collapses by its own gravity and the iron core heats up. The core becomes so tightly packed that protons and electrons merge to form neutrons. In less than a second, the iron core, which is about the size of Earth, shrinks to a neutron core with a radius of about 6 miles (10 kilometers). The outer layers of the star fall inward on the neutron core, thereby crushing it further. The core heats to billions of degrees and explodes (supernova), thereby releasing large amounts of energy and material into space. The shock wave from the supernova can initiate star formation in other interstellar clouds. The remains of the core can form a neutron star or a black hole depending upon the mass of the original star.