The electronic and optical properties of a material critically depend on its defects, and understanding that requires substantial and accurate input from theory. Defect calculations in traditional semiconductors have relied on the local and semi/local approximations of density functional theory, which in wide band gap materials may lead to fatal errors. Since first-principle total energy methods beyond these approximations cannot yet be carried out with sufficient accuracy for the supercells needed in defect calculations, nowadays semi-empirical hybrid functionals are often applied instead. In my talk I will analyze the performance of the HSE06 screened hybrid functional on defects in Group-IV semiconductors and in TiO2
, and show that its success is the result of error compensation between semi-local and non-local exchange, resulting in a proper derivative discontinuity (reproduction of the band gap) and a total energy which is a linear function of the fractional occupation numbers (removing most of the electron self-interaction). As it is well known, however, HSE06 does not work equally well for all materials. On the example of Ga2
, I will show that tuning both the mixing and the screening parameter of HSE for the given material allows to ensure the same error compensation. Unless the electronic screening is strongly direction- or orbital-dependent (as in ZnO), the optimized HSE hybrid is nearly self-interaction free and provides a band structure on par with GW. Since the total energy can also be calculated, the real equilibrium structure of a defect can be found and the levels are in good agreement with experimental observations.