Density functional theory calculations have been performed to study self-diffusion in magnesium oxide, a model material for a wide range of ionic compounds. Formation energies and entropies of Schottky defects and divacancies were obtained by means of total energy and phonon calculations in supercell configurations. Transition state theory was used to estimate defect migration rates, with migration energies taken from static calculations, and the corresponding frequency factors estimated from the phonon spectrum. In all static calculations we corrected for image effects using either a multipole expansion or an extrapolation to the low concentration limit. It is shown that both methods give similar results. The results for self-diffusion of Mg and O confirm the previously established picture, namely that in materials of nominal purity, Mg diffuses extrinsically by a single vacancy mechanism, while O diffuses intrinsically by a divacancy mechanism. Quantitatively, the current results are in very good agreement with experiments concerning O diffusion, while for Mg the absolute diffusion rate is generally underestimated by a factor of 5-10. The reason for this discrepancy is discussed.