A new method is presented to calibrate an X-ray energy scale with sub-meV relative accuracy by using the detailed-balance principle of the phonon creation and annihilation. This method is conveniently used to define or verify the energy scale of high-energy-resolution monochromators that are used in inelastic X-ray scattering and nuclear resonant inelastic X-ray scattering instruments at synchrotron radiation facilities. This method does not rely on sample properties and its precision only depends on the statistical data quality. Well calibrated instruments are essential for reliable comparison of data sets obtained at different synchrotron radiation beamlines, of data with theoretical predictions, and of data from other techniques such as neutron or light scattering. The principle of the detailed-balance method is described in this paper and demonstrated experimentally.