Robert Mulvaney, a glaciologist with the British Antarctic Survey, explains:
“The cornerstone of the success achieved by ice core scientists reconstructing climate change over many thousands of years is the ability to measure past changes in both atmospheric greenhouse gas concentrations and temperature. The measurement of the gas composition is direct: trapped in deep ice cores are tiny bubbles of ancient air, which we can extract and analyze using mass spectrometers. Temperature, in contrast, is not measured directly, but is instead inferred from the isotopic composition of the water molecules released by melting the ice cores.”
More here from Scientific American.