We use an array of high-resolution N-body simulations to determine the mass function of dark matter haloes at redshifts 10–30. We develop a new method for compensating for the effects of finite simulation volume that allows us to find an approximation to the true ‘global’ mass function. By simulating a wide range of volumes at different mass resolution, we calculate the abundance of haloes of mass 105−12 h−1 M⊙. This enables us to predict accurately the abundance of the haloes that host the sources that reionize the Universe. In particular, we focus on the small mass haloes (≳105.5−6 h−1 M⊙) likely to harbour Population III stars where gas cools by molecular hydrogen emission, early galaxies in which baryons cool by atomic hydrogen emission at a virial temperature of ∼104K (∼107.5−8 h−1 M⊙), and massive galaxies that may be observable at redshift ∼10. When we combine our data with simulations that include high-mass haloes at low redshift, we find that the best fit to the halo mass function depends not only on the linear overdensity, as is commonly assumed in analytic models, but also on the slope of the linear power spectrum at the scale of the halo mass. The Press–Schechter model gives a poor fit to the halo mass function in the simulations at all epochs; the Sheth-Tormen model gives a better match, but still overpredicts the abundance of rare objects at all times by up to 50 per cent. Finally, we consider the consequences of the recently released WMAP 3-yr cosmological parameters. These lead to much less structure at high redshift, reducing the number of z= 10‘mini-haloes’ by more than a factor of two and the number of z= 30 galaxy hosts by nearly four orders of magnitude. Code to generate our best-fitting halo mass function may be downloaded from http://icc.dur.ac.uk/Research/PublicDownloads/genmf_readme.html.