The chemical structures of aluminosilicate hydrates presented in alkali-activated geopolymer materials underpin their performances. Mg-substituted sodium aluminosilicate hydrates (N(-M)-A-S-H) are likely to be present in alkali-activated geopolymer materials prepared using MgO-containing precursors, however, their atomic-level structures remain unclear. The lack of such knowledge made it challenging to identify and distinguish N(-M)-A-S-H from complex alkali-activated geopolymer systems (i.e., alkali-activated slag, alkali-activated Mg-rich minerals), and therefore brought challenges in understanding and predicting their durability. This study characterised for the first time the atomic structures of the synthetic N(-M)-A-S-H gels, prepared through ion-exchange or co-synthesis, using X-ray absorption near-edge spectroscopy (XANES) at Si, Al and Mg K-edge. The results suggest that the substitution of Mg in the extra-framework locations of the alkali aluminosilicate hydrates (N-A-S-H) leads to negligible changes in the coordination environments of the aluminosilicate framework. However, the Mg coordination environment is distinguishably different from other Mg-containing phases in the systems, e.g., hydrotalcite. The Mg K-edge XANES of N(-M)-A-S-H shows a 0.8–1.2 eV shift compared with hydrotalcite. The results presented in this study can be used as the fingerprint to probe the presence of N(-M)-A-S-H in alkali-activated geopolymer materials containing Mg element.