In this topical review, we discuss recent progress in electronic-structure methods for calculating defect energy levels in semiconductors and insulators. We concentrate mainly on two advanced electronic-structure schemes, namely hybrid density functional theory and many-body perturbation theory in the GW approximation. These two schemes go beyond standard density functional theory in the semilocal approximation providing a more realistic description of band gaps. In particular, we address important aspects underlying the GW scheme and highlight the correspondence between the defect levels as obtained in the various schemes. We further assess the quality of the band-edge positions determined with hybrid functionals and GW through the calculation of band-offsets at semiconductor heterojunctions and of ionization potentials at semiconductor surfaces.