Almost all the elements in the universe are composed of atom siblings though are chemically equivalent but have slightly different weight.
Every Atom is composed of equal number of electrons and protons to make it electrically neutral and stable. There are also neutrons which are electrically neutral but have weight almost equal to the proton.
Protons and neutrons reside in the centre of atom and called jointly nucleus. This is due to the different numbers of neutrons in these atoms. More the neutrons more shall be the weight of the isotope.
Oxygen has two prominent isotopes. The lighter one contains 8 neutrons and the heavier one contains 10 neutrons this is exactly 2 neutron heavier. The ratio of the heavier atoms to the lighter ones is 1:500 or 0.2%.
The number and ratio of the oxygen isotopes is constant if water was present at one place only. But the distribution changes due to physical and biological processes. These two phenomena fractionated the distribution. The oxygen atoms are labeled 18O and 16O.
Since heavier oxygen has lower tendency to evaporate than the lighter and higher tendency to precipitate, the distribution changes continuously with the movement and phase changes of the water.
Originally in the sea water there was a given ratio. Now suppose sun heats the sea and evaporation takes place initiating the water cycle. But notice, the ratio of heavier atoms to lighter atoms will change both is the sea water left behind as well as the vapours.
Sea water will become richer in heavier isotope and vapours poorer. Now these vapours rise and starts migrating towards the poles. Temperature gradually begins to fall triggering the precipitation but again further fractionation will take place.
In the beginning, some of the heavier atoms will precipitate thus further depleting the pole ward moving water vapours in heavier atoms. So when the snow will start falling, it will be containing the least numbers of heavier atoms.
The snow will settle down. Future years will bring more snow, thus snowflakes shall begin to compact at the lower layers. Snowflakes contain roughly 80% air. After compaction, the air will be expelled and finally will form having only about 20% air. Ultimately lowest layers shall become ice containing only 2% air or less. Layer upon layer will build.
The snow precipitated in the relatively warmer climates shall have more heavier oxygen than the snow precipitated in cooler climates.
This phenomena is used to measure the temperature at which a particular layer was deposited. This provides a tool for temperature records in the history of the earth.
For this purpose, scientists take out the continuous cylindrical cores of the ice and measure the abundance of heavier oxygen atoms relative to the lighter ones using ratio recording mass spectrometer and plot this against depth.
From the calibration curves with temperature, scientists are able to measure the temperature records.
Knowing the past climatic history of the earth can help in understanding the ice ages epochs, chemical and biological reactions and thus the abundance or otherwise of minerals like petroleum.
Thus the ice deposited over millions of years preserves the memories of the climate in the past. They have been able to recreate the 4 million years record of temperatures.