The charge compensation mechanisms in U1-xGdxO2 and Th1-xGdxO2-x/2 have been systematically studied using X-ray Absorption Spectroscopy (XAS) upon gradually increasing the Gd content. Gd doped nuclear fuels are widely used for optimizing the fresh core neutronics, yet when Gd3+ is substituted into U4+ or Th4+ lattice position in UO2 or ThO2, respectively, charge must be compensated for charge neutrality. In U1-xGdxO2 the general hypothesis has been that the U4+ will oxidise to U5+/U6+ while in Th1-xGdxO2-x/2 the fixed Th4+ valence requires generation of O vacancies. Our XAS results for a series of technologically relevant Gd contents (x = 0.04 to 0.14) in U1-xGdxO2 clearly demonstrate that upon increasing the Gd content U5+ is formed inducing slight increase in the U coordination number and contraction for the U-O distances while the Gd local environment remains virtually unchanged. For the Th1-xGdxO2-x/2 larger Gd fractions were applied (x = 0.10 to 0.34). Nonetheless, both Gd and Th local environments show changes upon increasing the Gd content; the average Gd-O and Th-O distances decrease gradually and the Gd and Th coordination numbers follow the expected trend considering the O vacancy formation to obtain charge neutrality. Finally, comparison to Gd2O3 allowed us to propose that one of the Gd L3-edge XANES resonance features is directly connected to the generation of O vacancies.