The defect levels produced in insulators doped with transition metal (TM) ions are important for a variety of defect-related optical processes and magnetic properties. Here, we performed a systematical first-principles study of the defect levels in the band gap for all the $3{d}^{n}$ TM ions occupying octahedral sites in $\ensuremath{\alpha}\text{\ensuremath{-}}{\mathrm{Al}}_{2}{\mathrm{O}}_{3}, {\mathrm{MgAl}}_{2}{\mathrm{O}}_{4}$, MgO, ${\mathrm{KMgF}}_{3}$, and ${\mathrm{MgF}}_{2}$ based on density functional theory. The spin-polarized hybrid density functional with a dielectric-dependent Hartree-Fock mixing parameter was adopted to improve the band gap. The defect levels, i.e., the charge transition levels, were obtained by calculating the total energy differences of relaxed geometric structures for various valence states, considering image-charge and potential alignment corrections. These results were rationalized with available experimental optical spectra related to the charge transfer or photoionization transitions. The calculation scheme is appropriate for predicting the valence states of TM ions and their defect levels in insulators. The trends of variation of the defect levels across the $3d$ TM series may help interpreting experimental results and aid in the design and optimization of optical materials.