Older rock layers or strata are usually at the bottom. So each layer is younger than the layer below it and older than the one above. Fossils may be present in igneous rock (hardened volcanic lavas) and metamorphic rocks (formed by pressure and heat within the earth) but they are usually destroyed.
Telling the age of fossils in terms of years, or absolute time, is a much bigger problem. But scientists use several methods. The tree ring method, counting annual growth rings, can give a scientist a reasonably accurate date back to 3000 years ago.
The varve method, based on counting the annual layers of sand and clay deposited in a lake, bay or river by melting glaciers, can be used for deposits less than about 15,000 years old. Similar calculations based on the rate of sedimentation, erosion, salt accumulation, etc. have been successfully applied to very much older rocks.
The third method is concerned with radioactive decomposition and is based on actual changes in some of the rock elements or in the fossils themselves. Radioactive uranium gradually changes to uranium lead, radiocarbon to nitrogen and so on. From the proportion of uranium lead to uranium in the rock we can date the oldest rocks and fossils, nearly 3,000 million years old.