The virial theorem provides a fundamental link between the internal pressure (or kinetic energy) and the gravitational binding energy of a self-gravitating system. For a star, galaxy, or molecular cloud in steady equilibrium, it can be derived directly from the condition of hydrostatic equilibrium.
Starting from hydrostatic equilibrium, $$ \frac{dP}{dr}=-\rho(r)\frac{G\,M(r)}{r^{2}}, $$ multiply by the spherical volume element \(4\pi r^{3}dr\) and integrate from center (\(r=0\)) to surface (\(r=R\)): $$ \int_{0}^{R}4\pi r^{3}\frac{dP}{dr}\,dr=-\int_{0}^{R}4\pi r^{3}\rho(r)\frac{G\,M(r)}{r^{2}}\,dr. $$
Left-hand side (pressure term). Integrate by parts: $$ \int_{0}^{R}4\pi r^{3}dP=\Big[4\pi r^{3}P\Big]_{0}^{R}-\int_{0}^{R}12\pi r^{2}P\,dr \approx-3\!\int_{0}^{R}4\pi r^{2}P\,dr=-3\!\int P\,dV, $$ where \(P(R)\simeq 0\).
Right-hand side (gravity term). Using \(dM=4\pi r^{2}\rho\,dr\), $$ -\int_{0}^{R}4\pi r^{3}\rho\,\frac{G\,M}{r^{2}}\,dr = -\int_{0}^{R}\frac{G\,M(r)}{r}\,dM(r) \equiv \Omega , $$ which is the (negative) gravitational potential energy.
Equating both sides gives the pressure–gravity balance: \begin{equation} 3\!\int P\,dV+\Omega=0. \end{equation}
For an ideal gas the thermal kinetic energy is \(K=\tfrac{3}{2}\!\int P\,dV\), hence \begin{equation} 2K+\Omega=0, \end{equation} the virial theorem in its standard energy form.
A satellite of mass \(m\) in a circular orbit around a mass \(M\) at radius \(r\) obeys $$ K=\tfrac12 m v^{2}=\tfrac12\,\frac{G M m}{r},\qquad \Omega=-\frac{G M m}{r}, $$ so that \begin{equation} K=-\tfrac12\,\Omega , \end{equation} consistent with \(2K+\Omega=0\).
A star without an internal nuclear source behaves analogously: as it radiates, its total energy \(E=K+\Omega\) decreases; to re-establish virial balance the star contracts, making \(\Omega\) more negative and increasing \(K\) (heating the gas). As the star shrinks:
Thus a self-gravitating gas has negative specific heat: losing energy can raise its temperature. During stellar birth the contracting cloud spins up and heats until pressure and rotation counter gravity; during late stages, core contraction again heats the gas and ignites progressively heavier fuels. When nuclear power equals surface losses, the star reaches true equilibrium—hydrostatic balance sustained by the virial relation.
The virial theorem also yields the total mass of a galaxy cluster from member velocities. For \(N\) identical galaxies (mass \(m\)), $$ 2\sum_i \tfrac12 m v_i^{2}-\sum_{i\neq j}\frac{G m^{2}}{r_{ij}}=0. $$ Rearranging, $$ m\sum_i v_i^{2}-G m^{2}\sum_{i\neq j}\frac{1}{r_{ij}}=0. $$ Multiplying the first term by \(N/N\) and the second by \(N^{2}/N^{2}\), $$ N m\!\left[\frac{1}{N}\sum_i v_i^{2}\right] -\frac{G(Nm)^{2}}{2}\!\left[\frac{1}{N(N-1)/2}\sum_{i\neq j}\frac{1}{r_{ij}}\right]=0. $$ With \(M\equiv Nm\) (total mass) and defining \(\langle \cdot \rangle\) as the average over members, we obtain \begin{equation} M\,\langle v^{2}\rangle-\frac{G M^{2}}{2}\,\langle r_{ij}^{-1}\rangle=0, \end{equation} hence the virial mass \begin{equation} M=\frac{2\,\langle v^{2}\rangle}{G\,\langle r_{ij}^{-1}\rangle}. \end{equation}
Only the line-of-sight component \(v_{\text{los}}\) is observed. Assuming isotropy, $$ \langle v^{2}\rangle=3\,\langle v_{\text{los}}^{2}\rangle . $$ Thus the virial theorem converts measured velocity dispersions and projected separations into the total (including dark) mass of a cluster.
The virial theorem states that for any self-gravitating system in equilibrium, the total kinetic energy equals half the magnitude of the gravitational binding energy.