Of course, Lord Kelvin's calculation of the age of the Sun was was wrong. His calculation didn't count on a new energy source, which could replace the heat that is constantly being radiated away. That source is nuclear energy.
The Sun creates energy via a series of nuclear reactions called the
proton- proton chain. It goes like this. Normally, hydrogen nuclei
(which are actually just protons, since everything in the center of the
Sun is completely ionized) don't get very close to each other: the positive
charges repel each other. However, in the center of the Sun, the heat is
intense and the protons are moving at a tremendous speed. Under these
conditions, the protons can be forced together. When this happens, the
result is usually -- nothing. The protons bounce away from each other and
go their own way. But very, very occasionally, something different happens.
At the moment of contact, one of the protons changes into a neutron,
an anti-electron (called a positron), something called a neutrino, and a
gamma-ray. The neutron then hits another proton and fuses to make
deuterium, which is an isotope of hydrogen that has 1 proton and
1 neutron. Following this, two other reactions quickly occur -- deuterium
and another free proton fuse to make a Helium-3 (two protons and 1 neutron),
and two Helium-3 particles fuse to make Helium-4 (normal helium) plus two free
protons. (Note that the number denotes the total number of particles in
the nucleus. The number of protons is defined by element.)
The net result of the above reactions is that 4 hydrogen nuclei (protons) get changed into 1 helium nucleus (plus the garbage positron and neutrino). Furthermore, if you were to weigh all the particles involved in this reaction, you would find that the four hydrogens (together) weigh more than 1 helium (plus garbage). Where did the mass go? Einstein had the answer: E = m c^2. The mass defect, which is 0.7% of the initial mass of the 4 hydrogen atoms, got changed to energy. This energy replaces the energy that is radiated away and keeps the Sun from collapsing.
Suppose the Sun had twice as much mass as it actually does. Obviously, the center of the Sun would be under greater pressure, and, through the equation of state, the temperature at the center would be greater. Greater temperature means faster moving particles. Protons would collide more frequently (and more violently), and there would be more nuclear reactions. The Sun would be brighter. This explains the main-sequence mass-luminosity relation.
Nuclear reactions can continue as long as there is hydrogen to fuse.
Note, however, that the Sun (and most stars) transport heat radiatively,
so the interior of the Sun is not getting mixed. The Sun has been
fusing hydrogen to helium in its core for 5 billion years, and will
continue to fuse hydrogen for 5 billion more years. However, eventually,
the hydrogen in the core will run out. There will still be plenty of
hydrogen outside the core, but this will do the Sun no good.
When the core runs out of hydrogen, the structure of the Sun must change.
But before going on -- a warning. Most of the following discussion
deals exclusively with changes that occur in the very core of
the star. Since the star is not transporting its energy via convection,
the outer parts of the star are not really affected by all this evolution.
The star's outer layers may expand or contract, (and therefore the star's
surface temperature may change), but the composition of the outside of the star
will (on the whole) be the same as it was at the beginning of its life.
Thus, an observer looking at the outside of a star will NOT see the direct
the consequences of the subsequent evolution.
When the core runs out of hydrogen, gravity will begin to take over and the center of the star will slowly collapse. This will generate energy, just like Lord Kelvin predicted. But something else also occurs. Although there won't be any hydrogen in the Sun's core, there will be hydrogen just outside the core, and this hydrogen will be able to fuse. The Sun will therefore have two energy sources: the gravitational contraction of the core, and the energy due to fusion in the shell. This will make the star extremely bright. Moreover, the energy from the fusion shell will produce radiation pressure which will literally blow the outside of the Sun outward, making the Sun expand. The Sun will expand so much that it will swallow up the planets Mercury, Venus, and the Earth. (It won't quite get out to Mars.) Obviously, since the outside of the Sun will be more than 1 A.U. away from where the energy is being produced, the outside will be rather cool. The Sun will be a bright red giant star.
At this stage, the density in the center of the Sun will be tremendous. Unfortunately, there is no readily available energy source to replace the heat that is leaking out. With the hydrogen all gone, all that is left is helium (Helium-4, to be specific). For two reasons, the Sun cannot fuse this helium. First, Helium-4 has twice as many protons as hydrogen; this means that the repulsion of the like charges is four times greater. Second, if two Helium-4 nuclei collide, they fuse to make Be8 (beryllium-8: 4 protons and 4 neutrons). However, Beryllium-8 is unstable --- once made, it almost immediately splits apart and you're back with two atoms of Helium-44. So no energy is made.
Since helium does not readily fuse, the core of the red giant star continues to collapse (and generate energy via the collapse). This collapse means that the gravity (and therefore the pressure) in the hydrogen-burning shell just the core continues to increase. (This is because the mass interior of the shell is staying the same, but the distance of the shell to the center of the star is decreasing.) So, during this phase, the star's shell-burning luminosity becomes greater and greater, the star's radius gets larger and larger, and the star's core gets smaller and smaller. This will happens to all stars (eventually). That is why there is no pattern to the masses of red giant stars. Low mass stars, and high mass stars all eventually become red giants.
Finally, the density and temperature at the core of the red giant star becomes
so great that something happens. As we said previously, two Helium-4 atoms
cannot fuse, since the resulting element, Beryllium-8, is unstable and
immediately decays back into the two helium atoms. However, if the density
and temperature are great enough, three helium atoms can come together
at once. When this happens, the three particles fuse --- to make carbon-12
(C12). The atomic weight of C12 is less than the weight of 3 helium nuclei, so
the reaction produces energy. So does the next reaction,
C12 + He4 -> O16 (oxygen-16). These two reactions give the star a
new source of energy! Note that the 3He4 -> C12 reaction is called the
triple-alpha process (because another name for a He4 nucleus is
an alpha particle).
The energy from the triple-alpha process immediately changes the star. The core gets hot, so the gas pressure increases, and the core expands. This decreases the gravity at the hydrogen-burning shell, which decreases the density in the shell, which decreases the amount of fusion in the shell, which decreases the radiation pressure at the surface, which causes the star to shrink. The result is that the star's luminosity decreases, and its surface temperature increases (since the surface is now closer to the energy-producing core). The star moves back towards the center of the HR diagram.
Unfortunately, helium fusion is not nearly as efficient as hydrogen fusion, so it doesn't take the star too long to change all the helium in its core to carbon and oxygen. When the helium runs out, the star is in trouble again. Although the star would like to fuse carbon, carbon has 6 protons in its nucleus. The atomic particles have to be going REAL fast to overcome that amount of electrostatic repulsion, and the core it not nearly that hot. So fusion in the core stops.
With no more energy to replace the heat leaking out of it, the star's
core collapses. But again note that there is plenty of helium just outside
the core, so, as the core collapses, the density and temperature in this
region become great enough to fuse helium. And don't forget that, just
outside this region, there is a shell where hydrogen is still fusing, making
helium. So there's the inert carbon-oxygen stellar core, a shell right
around the core burning helium to carbon-oxygen, and a shell right around
that shell burning hydrogen to helium. Like before, the energy of the
collapsing core is added to that created in the shell burning, and the
star becomes very bright. And, also like before, the radiation
pressure from the hydrogen and helium burning shells forces the outside
of the star to expand. Once again, the star is a red giant. (Some
textbooks refer to these stars as ``Supergiants''.)
Note that during this phase, the surface of the star is far, far, far away from the stellar center. The gravity at the star's surface is therefore very weak, and it doesn't take much for some of the star's atmosphere to reach escape velocity and become unbound to the star. In fact, this is what happens to a substantial fraction of the star's outer regions -- during this second giant phase, it is ejected from the star and never comes back.
Also, since the outside of the star is so far away from the energy-producing core, it is very cool (only two or three thousand degrees). At these temperatures, carbon and silicon molecules start combining with things to make dust (soot and sand). That's how space gets so dusty!
At this point, one of two things can happen to the star, depending on the
star's mass. First, let's consider a star which started out with a
moderately low mass (say, less than 8 solar masses). During the supergiant
phase, much of its star's mass will be lost, so that the material left
on the star is less than 1.4 solar masses. This number is critical, and
it is called the Chandrasekhar limit.
As the core continues to collapse, the gas gets compressed more and more, and the material becomes denser and denser. Electrons that were freed from their atoms via ionization, get crushed back into their atoms. Then, as the gravity increases still further, the atoms get further crushed so that those electrons in high-energy orbitals are pushed (by the pressure) into lower-energy orbitals. In fact, gravity would like to do even more, and push the electrons to even lower states, but as we learned when we studied the structure of the atom, electrons can only go in certain very specific orbits. In other words, the electrons say "no, you cannot crush me any further -- I'm already as squished as I can get." This electron degeneracy then holds the star up.
Note that what's left of the star now is very peculiar. Most of the matter
outside the core is gone. Shell burning is almost at an end, since there
is no more matter to burn. The core is still extremely hot (just as a stove
is still extremely hot even after you've turned it off), so it is emits
high energy photons. These photons ionize the gas (which used to be its
atmosphere) surrounding it; recombination then creates an emission line
spectrum. The object is a planetary nebula. (The name is a
misnomer, since it has nothing at all to do with planets.)
Eventually, the matter around the star disperses, and the remnant slowly cools off. Electron degeneracy keeps the star from collapsing to a point, but the star is very small. A star like the Sun, which began life on the main sequence with a diameter of a million miles, is now the size of the earth. The surface gravity of this carbon-oxygen core is so great, that one teaspoon of matter weighs 2000 tons. And that's the way the star ends its life -- slowly cooling (and crystallizing), as a white dwarf star.
The white dwarf stage is reserved for stars whose final mass takes them
under the Chandrasekhar limit. Higher mass objects have a different fate.
Their high mass translates into greater gravitational pressure in the core,
and as a result, even carbon and oxygen can fuse. When this happens, a whole
set of new elements are produced, including neon, sodium, and magnesium.
This new source of energy temporarily gives life to the star: the core
expands, shell burning becomes less important, and the outside of the star
contracts. But then, very quickly, all the carbon and oxygen in the core is
gone. The star is back to where it started, except that its core is
mostly magnesium, and that surrounding the core is a shell of carbon burning,
followed by a shell of helium burning, followed by a shell of hydrogen
burning. The core again collapses, and the cycle repeats. This time,
silicon (and some other elements around silicon) is produced. The energy
momentarily expands the core and shrinks the star, but soon thereafter the
fuel is again gone, leaving the star with a silicon core, and burning shells
of magnesium, carbon-oxygen, helium, and hydrogen. Then it happens again, and
as the silicon burns to iron, the star once again reacts to its new-found
energy. The star then has an iron core, and an onion-skin morphology, with a
whole series of fusing shells.
All this time, the star has been producing energy from Einstein's equation,
E = m c^2. Each time a fusion reaction occured, the mass of the
fusion product was less than that of the fuel. The mass-defect was changed
to energy. This energy increased the gas temperature, which increased the
gas pressure, which held up the star. But, once the star reaches iron, this
changes.
When you fuse iron, the product (no matter what it is), weighs more than what you start with. In other words, iron fusion doesn't make energy -- it loses energy. [If you think about it, this makes perfect sense. When one fuses light elements, such as hydrogen, one makes energy. On the other hand, when one tears heavy elements (such as uranium) apart via fission one also makes energy. Somewhere in the middle, there must be a place where neither fission nor fusion makes energy. That place is iron.] When a star tries to fuse iron, energy is lost, and the temperature of the core goes down. This decreases the gas pressure, which increases the rate of core collapse, which increases the density, which increases the amount of iron fusion, which lowers the temperature even more, which decreases the gas pressure more, which ...
In an instant, the entire star collapses --- and explodes, sending most of
its material into space at extremely high speed (thousands of kilometers
per second). During this
supernova explosion the star can outshine a whole galaxy of 100
billion stars. Also, the energy of the explosion forces all sorts of atomic
nuclei together. Every atomic nucleus heavier than iron can be made in
a supernova explosion. In fact, that's the only way we know to make the
elements heavier than iron. So, in a very real sense, everything
around us came from inside an exploding star.