We report an ab initio study of the semiconducting Mg(2)X (with X = Si, Ge) compounds and in particular we analyze the formation energies of the different point defects with the aim of understanding the intrinsic doping mechanisms. We find that the formation energy of Mg(2)Ge is 50% larger than that of Mg(2)Si, in agreement with the experimental tendency. From a study of the stability and the electronic properties of the most stable defects, taking into account the growth conditions, we show that the main cause of the n doping in these materials comes from interstitial magnesium defects. Conversely, since other defects acting like acceptors such as Mg vacancies or multivacancies are more stable in Mg(2)Ge than in Mg(2)Si, this explains why Mg(2)Ge can be of n or p type, in contrast to Mg(2)Si. The finding that the most stable defects are different in Mg(2)Si and Mg(2)Ge and depend on the growth conditions is important and must be taken into account in the search for the optimal doping to improve the thermoelectric properties of these materials.