  Defects in 2D materials are becoming prominent candidates for quantum
emitters and scalable optoelectronic applications. However, several physical
properties that characterize their behavior, such as charged defect ionization
energies, are difficult to simulate with conventional first-principles methods,
mainly because of the weak and anisotropic dielectric screening caused by the
reduced dimensionality. We establish fundamental principles for accurate and
efficient calculations of charged defect ionization energies and electronic
structure in ultrathin 2D materials. We propose to use the vacuum level as the
reference for defect charge transition levels (CTLs) because it gives robust
results insensitive to the level of theory, unlike commonly used band edge
positions. Furthermore, we determine the fraction of Fock exchange in hybrid
functionals for accurate band gaps and band edge positions of 2D materials by
enforcing the generalized Koopmans' condition of localized defect states. We
found the obtained fractions of Fock exchange vary significantly from 0.2 for
bulk $h$-BN to 0.4 for monolayer $h$-BN, whose band gaps are also in good
agreement with experimental results and calculated GW results. The combination
of these methods allows for reliable and efficient prediction of defect
ionization energies (difference between CTLs and band edge positions). We
motivate and generalize these findings with several examples including
different defects in monolayer to few-layer hexagonal boron nitride ($h$-BN),
monolayer MoS$_2$ and graphane. Finally, we show that increasing the number of
layers of $h$-BN systematically lowers defect ionization energies, mainly
through CTLs shifting towards vacuum, with conduction band minima kept almost
unchanged.
