Doping has been established as a powerful approach for endowing lead halide perovskite nanocrystals (NCs) with novel properties. However, our fundamental understanding of the local structure of dopants, doping efficiency and luminescence properties of these NCs is still very sparse. Here, we provide the first experimental evidence regarding the local structure of rare earth ions in CsPbCl3 NCs, based on the analysis of extended X-ray absorption fine structure spectroscopy. Our result suggests that Yb3+ occupies the Pb2+ crystallographic sites in CsPbCl3 NCs. We further demonstrate a strategy to examine the determinant of the doping efficiency in lanthanide-doped lead halide perovskite NCs, which enables us to uncover the important role of structural defects in affecting the doping efficiency. A broad range of experimental characterization techniques including steady-state and time-resolved luminescence spectra, X-ray absorption spectra, and positron annihilation lifetime spectra, coupled with first-principles calculations, help us identify that the doping efficiency is associated with structural defects in NCs and that the formation of a higher-concentration of defects favors incorporation of a higher-concentration of dopants into the lattice. Importantly, we demonstrate that the concept of defect-assisted doping is not limited to the model system of Yb3+-doped CsPbCl3 NCs, but can be used as a guideline to rationally tune the doping efficiency of lanthanide-doped halide perovskite NCs. We also show that lanthanide-doped CsPbCl3 NCs demonstrate anomalous decay of the band-edge emission, which we propose is due to the existence of shallow trapping states near the conduction band. Our results greatly deepen the understanding of the structural and photophysical properties of lanthanide-doped lead halide perovskite NCs, and highlight the possibility to use the chemistry of defects to tailor the doping efficiency of halide perovskite NCs.