We report on a comparison between the flux of muons in the atmosphere measured by the CAPRICE98 experiment and simulations performed with the air shower simulation program AIRES. To reduce systematic uncertainties we have used as input the primary fluxes of protons and helium nuclei also measured by the CAPRICE98 experiment. Heavy nuclei are also taken into account in the primary flux, and their contribution to the muon flux is discussed. The results of the simulations show a very good agreement with the experimental data, at all altitudes and for all muon momenta. With the exception of a few isolated points, the relative differences between measured data and simulations are smaller than 20%; and in all cases compatible with zero within two standard deviations. The influence of the input cosmic ray flux on the results of the simulations is also discussed. This report includes also an extensive analysis of the characteristics of the simulated fluxes.