Stable isotopes and trace elements in foraminifera shells are important for determining the paleochemistry of the ocean, and Mg/Ca ratios and δ18O values in foraminifera have recently been used to determine simultaneously the temperature and salinity of past oceans. However, large variations between species and significant Mg intra-shell heterogeneity indicate a major role for biological factors in determining the Mg/Ca ratio in foraminifera. Our novel in vivo observations on the biomineralization process of perforate foraminifera show that their calcareous wall is composed of two different calcite types: a thin, high-Mg primary layer, and low-Mg layers that cover the primary layer on both sides. The data may suggest that two biomineralization pathways are employed in the formation of the different calcite types. A new conceptual framework is provided to explain part of the Mg heterogeneity in foraminiferal shells and the variable sensitivity of the Mg/Ca ratio to temperature in different species.