Each star is formed from a massive gas cloud. The cloud condenses over a period of maybe one million years, heating up as it contracts. As it contracts, it starts to spin because of the law of conservation of angular momentum. At some point it will become a protostar, with a temperature or maybe 2000K at it's surface. Further contraction and heating will result in the core heating further, and if the mass of the star is more than about 8% of the mass of the Sun, reaching a temperature of 15000000 Degrees Kelvin, a temperature hot enough to initiate nuclear reactions. The cloud of gas is now a star. There is a balance between the force of gravity forcing contraction, and gas and radiation pressure forcing expansion. The star will remain in this stage, shining for millions to billions of years to come. This is the stage our Sun is at right now.
As the main sequence star glows, hydrogen in its core is converted into helium by nuclear fusion. When the hydrogen supply in the core begins to run out, and the star is no longer generating heat by nuclear fusion, the core becomes unstable and contracts, heating further. The outer shell of the star, which is still mostly hydrogen, starts to expand. As it expands, it cools and glows red. The star has now reached the red giant phase. It is red because it is cooler than it was in the main sequence star stage and it is a giant because the outer shell has expanded outward. In the core of the red giant, helium fuses into carbon. All stars evolve the same way up to the red giant phase. The amount of mass a star has determines which of the following life cycle paths it will take from there.
For low-mass stars, after the helium has fused into carbon, the core collapses again. As the core collapses, the outer layers of the star are expelled. A planetary nebula is formed by the outer layers. The core remains as a white dwarf and eventually cools to become a black dwarf.
Once stars that are 5 times or more massive than our Sun reach the red giant phase, their core temperature increases as carbon atoms are formed from the fusion of helium atoms. Gravity continues to pull carbon atoms together as the temperature increases and additional fusion processes proceed, forming oxygen, nitrogen, and eventually iron. Each of these reactions release successively less energy. No more energy can be released by fusing iron to form heavier elements. Since energy is no longer being radiated from the core, in less than a second, the star begins the final phase of gravitational collapse. The core temperature rises to over 100 billion degrees as the iron atoms are crushed together resulting in a shock wave which we see as a supernova explosion.
If the remnant of the explosion is between about 1.4 to about 3 times as massive as our Sun, it will become a neutron star. The core of a massive star that has more than roughly 3 times the mass of our Sun after the explosion will do something quite different. The force of gravity overcomes the nuclear forces which keep protons and neutrons from combining. The core is thus swallowed by its own gravity. It has now become a black hole which readily attracts any matter and energy that comes near it. What happens between the red giant phase and the supernova explosion is described below.
As the shock encounters material in the star's outer layers, the material is heated, fusing to form new elements and radioactive isotopes. While many of the more common elements are made through nuclear fusion in the cores of stars, it takes the unstable conditions of the supernova explosion to form many of the heavier elements. The shock wave propels this material out into space. The material that is exploded away from the star is now known as a supernova remnant.