The Kelvin-Helmholtz timescale is a theoretical estimate of how long a given star would shine with its current luminosity if the only power source were the conversion of gravitational potential to heat.

First, find the net gravitational potential energy

Egravity = G m2 / r

where E is the potential energy, m2 is the "mean mass" (squared), and r is the "mean radius" at a point within the star. We simplify things by assume a mean mass M equal to one-half of the total stellar mass, and a mean radius R equal to one-half of the current radius. (If you were going to be precise, you would instead perform a three dimensional integration of the potential over the sphere of the star.) This yields an approximate gravitational potential energy reserve of

Egravity = G M2 / 2R

The luminosity of a star is the energy emitted per second (usually given in units of ergs per second). The length of time a star could shine using just gravitational potential energy is then

time = Egravity/L = G M2 / 2RL

The Sun has a luminosity of 3.85 × 1033 ergs/second, or 3.85 × 1026 watts. It has a mass of about 2 × 1033 grams, and a radius of about 7 × 1010 centimeters. Combining these, we find that the lifetime of the Sun would be only about 15 million years if it were only powered by gravitation.

We now know that stars are not powered purely by gravity, but by energy released by the nuclear reactions occurring in the star's core. Nuclear reactions were unknown at the time Kelvin and Helmholtz came up with their theory (the latter half of the 19th century), so their assumption was perfectly reasonable. However, Kelvin-Helmholtz contraction is the main power source for certain short stages of stellar evolution, particularly during pre-main sequence contraction, which lasts about ten million years (give or take an order of magnitude depending upon the mass of the star).