The narrow-gap semiconductor magnesium silicide (Mg2Si) is a promising candidate for mid-temperature (500-800 K) thermoelectric applications. Mg2Si exhibits intrinsic n-type conductivity because of its interstitial Mg defects and is generally doped with n-type dopants; however, the synthesis of p-type Mg2Si has proven difficult. In the present study, we examined several types of defects, such as vacancies and the insertion of constituent atoms (Mg and Si) into crystals, to elucidate their stability in Mg2Si and their influence on its electronic states. A first-principles calculation has revealed that the insertion of Mg into a cell is the most stable and causes n-type conductivity in terms of formation energy. In contrast, the vacancy of Mg produces hole doping although its formation energy per conventional unit cell is approximately 0.07 eV higher than that of the insertion of Mg, at their concentration of 1.04 at. %. Furthermore, the insertion and vacancy of Si atoms generate electrons with higher formation energies compared to the Mg-related defects. As these defects alter the carrier concentration, they can compensate for intentional doping because of the added impurity atoms.