Stars shine by converting chemical elements into heavier elements through a process called nuclear fusion. This process only takes place under incredibly high pressure and at extremely high temperatures. Under these circumstances, the electrons surrounding an atomic nucleus can be stripped away, and the nuclei forced together.
Stars are thought to condense from huge clouds of gas in the vacuum of space. Generally, these clouds of gas can be regarded as debris left over from the Big Bang, when temperatures in space were a good deal hotter than the current, chilly four degrees above absolute zero. As the expanding universe cooled, most of the protons and electrons formed in the Big Bang paired up to form hydrogen atoms. These atoms consist, surprisingly enough, of a single proton being orbited by an electron.
Gradually, under the influence of their mutual gravity, these clouds shrank. Depending upon the mass of the clouds, various interesting things started to happen. One feature of all the contracting clouds was that they got hotter; gravitational contraction crammed the hydrogen atoms into an increasingly smaller volume, and lowering the volume increases pressure and temperature. This caused the clouds to heat up.
It is theorised that the smaller clouds (less than 13 times the mass of Jupiter) would form a roughly spherical blob - a 'brown dwarf' - which glowed dull red, and then cooled off over billions of years. Being small, dull and unpresuming, these objects tend to be rather difficult to spot, like house mites. There are, nevertheless, very many more house mites than people think, and it seems that there are a lot more brown dwarfs out there than we previously bargained for. Some cosmologists think that there are as many brown dwarfs as there are conventional stars.
Clouds greater than 13 times the mass of Jupiter would become slightly more interesting - but only temporarily. At this mass, the pressure inside the condensing cloud becomes so great that ordinary hydrogen nuclei begin to rub shoulders with nuclei of a heavier form of hydrogen called deuterium, which has a nucleus composed of a neutron and a proton. At this sort of pressure, the electrostatic repulsion between the protons in the nuclei becomes huge, but providing they can get close enough, an incredibly strong force - imaginatively called the 'strong nuclear force' - begins to take over. The nuclei fuse into single, two proton and one neutron nuclei of helium-3 (3He), fairly large amounts of energy are released, and the blob gets somewhat hotter. Unfortunately for these blobs, their moments of tepid glory tend to be short lived. The abundance of deuterium relative to hydrogen is about 1%, so fairly early on in their lives these brown dwarfs run out of fuel. They then cool off over a period of hundreds of millions of years.
Blobs approaching 70 times the mass of Jupiter have sufficient pressure in their cores to force together nuclei of ordinary hydrogen atoms. When this happens, the protons fuse together, one of the two protons turns into a neutron, and deuterium is formed, which can react with other hydrogen atoms. The star effectively begins to make its own fuel, and really starts to shine. As it does so, hydrogen is converted into helium in the star's core.
As the starting size of the cloud gets bigger and bigger, the temperature at the core gets hotter and the star burns both brighter and bluer. This is why our Sun, which has about 1000 times the mass of Jupiter, has a yellowish tinge to its light. Larger and bigger stars have a blue tinge to their light.
In 1911, Ejnar Hertzsprung, followed (independently) by Henry Norris Russel in 1913, made plots of stellar magnitude (luminosity) against spectral type1. These plots are now called Hertzsprung-Russel (H-R) diagrams. They found that there was a linear feature on their diagrams that showed a relationship between spectral type (which, by the magic of astronomy, is analogous to temperature) and luminosity (which, also by the magic of astronomy, is analagous to size) the bigger the star the brighter, even if they're all different colours. This linear feature was called the Main Sequence. So, on the Main Sequence, a hotter star is more luminous. Their diagram had one or two other regions as well: the red giants, which were too bright for their colour/temperature to be on the sequence, and the white dwarfs, which were too dim for their temperature to be on the Main Sequence. Later it was found that stars on the main sequence were all 'burning' hydrogen to helium, like the sun, a definite Main Sequence star.
What Happens to them when they Age
Throughout its lifetime, a Main Sequence star will get brighter and brighter, as the core increases in size. At a certain critical point, the amount of reacting hydrogen in the core drops to the point where hydrogen fusion cannot be sustained. The internal pressure drops and the gravitational forces inside the star cause it to contract rapidly. When this happens, the energy released by the contraction of the star gets directed outwards into a shell of hydrogen surrounding the inert core.
The result of this energy being dissipated in the outer layers of the star is that the hydrogen shell starts burning to helium. The shell is very much bigger than the core and hence a lot more energy is generated. The increase in temperature throughout the star causes it to develop a severe case of 'middle-aged-spread' and it expands to many times its original radius, scorching any nearby planets in the process. The star has now become a 'red giant'. Red giant stars eventually get so hot in their cores they start to convert helium to carbon and oxygen. Eventually, the star's core becomes cluttered with all sorts of nuclei converting themselves into heavier nuclei.
How Stars Die
Depending on the mass of the star, there comes a point when nuclear fusion ceases, due to the inability of the star to burn its waste products. Small mass stars, like the sun, get hotter and hotter in the core but their gravity is insufficient to hold onto their outer layers. The outer layers of the star get blown away to form a planetary nebula. The small, dense, incredibly hot remnant left behind forms a white dwarf star. This is the fate that faces our Sun, and us, in about four billion years time.
High mass stars end their lives not with a whimper, but a very large bang. These are so heavy that they successively convert all sorts of nuclei into iron. Iron is the most stable atomic nucleus known; it cannot fuse with other nuclei without absorbing energy. The iron builds up in the star's core, and eventually the core becomes so dense and inert the entire star collapses, with the outer layers moving inwards at up to one-sixth of the speed of light. These then bounce off the inert core in a mighty shock wave and the star blows itself to pieces in a supernova explosion. This is rather like what happens if you throw a brick at a television screen: it may implode, but an awful lot of energy gets directed into lethally outward-flying shards of glass.
The energy released during this event is immense; a single supernova can outshine all the other stars in the galaxy combined. Some of the energy gets directed into fusing iron into even heavier elements. The force of the explosion distributes this mixture of spent star-stuff throughout the galaxy. Some of this eventually gets incorporated into forming stars, and the process begins all over again. Our Sun is a second-generation star, formed by exactly this process when a young, hot star died billions of years ago.