The Mg/Ca ratio of foraminiferal calcite is a widely accepted and applied empirical proxy for ocean temperature. The analysis of foraminifera preserved in ocean sediments has been instrumental in developing our understanding of global climate, but the mechanisms behind the proxy are largely unknown. Analogies have been drawn to the inorganic precipitation of calcite, where the endothermic substitution of Mg for Ca is favoured at higher temperatures. However, evidence suggests that foraminiferal Mg incorporation may be more complex: foraminiferal magnesium is highly heterogeneous at the sub-micron scale, and high Mg areas coincide with elevated concentrations of organic molecules, Na, S and other trace elements. Fundamentally, the incorporation mode of Mg in foraminifera is unknown. Here we show that Mg is uniformly substituted for Ca within the calcite mineral lattice. The consistency of Mg-specific X-ray spectra gathered from nano-scale regions across the shell ('test') reveals that the coordination of Mg is uniform. The similarity of these spectra to that produced by dolomite shows that Mg is present in an octahedral coordination, ideally substituted for Ca in a calcite crystal structure. This demonstrates that Mg is heterogeneous in concentration, but not in structure. The degree of this uniformity implies the action of a continuous Mg incorporation mechanism, and therefore calcification mechanism, across these compositional bands in foraminifera. This constitutes a fundamental step towards a mechanistic understanding of foraminiferal calcification processes and the incorporation of calcite-bound palaeoenvironment proxies, such as Mg.