Rock layers, or strata, are built up from material that is deposited on top of the existing layers. This means that the oldest layers are on the bottom, and younger rocks are on top. There are instances when a whole formation has been turned upside down, but there is normally enough evidence to know when this has occurred. If scientists are able to date a particular layer, they usually find that everything below that layer is older, and everything above it is younger.
Lava flows and volcanic ash can be dated by measuring certain isotopes of trapped gases. Prior to the volcanic eruption that deposited them, these rocks had to be molten (liquid), and gases could escape. But gas formed after the rocks solidified became trapped.
In areas with a history of repeated volcanic eruption, multiple ash layers are present in the rock strata. These can be dated, and then geologists can infer that all of the rock between two dated layers was formed between those dates. The ash layers establish points on a timeline of formation of the entire rock sequence.
Two gases used in dating are argon-40, which is formed from the decay of radioactive potassium-40, and helium-3, which is formed by the action of cosmic rays.