Density-functional theory combined with periodic boundary conditions is used to systematically study the dependence of defect formation energy on supercell size for diamond containing vacancy and self-interstitial defects. We investigate the effect of the electrostatic energy due to the neutralization of charged supercells and the effect of the alignment of the valence band maximum (VBM) on the formation energy. For negatively charged vacancies and positively charged interstitials, the formation energies show a clear dependence on supercell size, and the electrostatic corrections agree with the trend given by the Makov-Payne scheme (Ref. 28). For positively charged vacancies and negatively charged interstitials, the size dependence and the electrostatic corrections are quite weak. An analysis of the spatial charge density distributions reveals that these large variations in electrostatic terms with defect type originate from differences in the screening of the defect-localized charge, as explained by using a simple electron-gas model. Several VBM alignment schemes are also tested. The best agreement between the calculated and asymptotically exact ionization levels is obtained when the levels are based on the formation energies referenced to the VBM of the defect-containing supercell.