For materials of varying band gap, we compare energy levels of atomically localized defects calculated within a semilocal and a hybrid density-functional scheme. Since the latter scheme partially relieves the band gap problem, our study describes how calculated defect levels shift when the band gap approaches the experimental value. When suitably aligned, defect levels obtained from total-energy differences correspond closely, showing average shifts of at most 0.2 eV irrespective of band gap. Systematic deviations from ideal alignment increase with the extent of the defect wave function. A guideline for comparing calculated and experimental defect levels is provided.