We present a measurement of the ratio of positive to negative muon fluxes from cosmic ray interactions
in the atmosphere, using data collected by the CMS detector both at ground level and in the underground
experimental cavern at the CERN LHC. Muons were detected in the momentum range from 5 GeV/c to
1 TeV/c. The surface flux ratio is measured to be 1.2766 ± 0.0032 (stat.) ± 0.0032 (syst.), independent
of the muon momentum, below 100 GeV/c. This is the most precise measurement to date. At higher
momenta the data are consistent with an increase of the charge ratio, in agreement with cosmic ray
shower models and compatible with previous measurements by deep-underground experiments.