Cosmological models in which dark matter consists of cold elementary particles predict that the dark halo population should extend to masses many orders of magnitude below those at which galaxies can form. Here we report a cosmological simulation of the formation of present-day haloes over the full range of observed halo masses (20 orders of magnitude) when dark matter is assumed to be in the form of weakly interacting massive particles of mass approximately 100 gigaelectronvolts. The simulation has a full dynamic range of 30 orders of magnitude in mass and resolves the internal structure of hundreds of Earth-mass haloes in as much detail as it does for hundreds of rich galaxy clusters. We find that halo density profiles are universal over the entire mass range and are well described by simple two-parameter fitting formulae. Halo mass and concentration are tightly related in a way that depends on cosmology and on the nature of the dark matter. For a fixed mass, the concentration is independent of the local environment for haloes less massive than those of typical galaxies. Haloes over the mass range of 10^3 to 10^11 solar masses contribute about equally (per logarithmic interval) to the luminosity produced by dark matter annihilation, which we find to be smaller than all previous estimates by factors ranging up to one thousand.