The Korteweg-de Vries equation, which describes the unidirectional propagation of long waves in a wide class of nonlinear dispersive systems, is well known to have solutions representing solitary waves. The present analysis establishes that these solutions are stable, confirming a property that has for a long time been presumed. The demonstration of stability hinges on two nonlinear functionals which for solutions of the Korteweg-de Vries equation are invariant with time: these are introduced in section 2, where it is recalled that Boussinesq recognized their significance in relation to the stability of solitary waves. The principles upon which the stability theory is based are explained in section 3, being supported by a few elementary ideas from functional analysis. A proof that solitary wave solutions are stable is completed in section 4, the most exacting steps of which are accomplished by means of spectral theory. In appendix A a method deriving from the calculus of variations is presented, whereby results needed for the proof of stability may be obtained independently of spectral theory as used in section 4. In appendix B it is shown how the stability analysis may readily be adapted to solitary-wave solutions of the 'regularized long-wave equation' that has recently been advocated by Benjamin, Bona & Mahony as an alternative to the Korteweg-de Vries equation. In appendix C a variational principle is demonstrated relating to the exact boundary-value problem for solitary waves in water: this is a counterpart to a principle used in the present work (introduced in section 2) and offers some prospect of proving the stability of exact solitary waves.