The layers of rock are known as "strata", and the study of their succession is known as "stratigraphy".
Fundamental to stratigraphy are a set of simple principles, based on elementary geometry, empirical observation of the way these rocks are deposited today, and gravity.
There are situations where it potentially fails -- for example, in cave deposits.
In this situation, the cave contents are younger than both the bedrock below the cave and the suspended roof above.
Most of these principles were formally proposed by Nicolaus Steno (Niels Steensen, Danish), in 1669, although some have an even older heritage that extends as far back as the authors of the Bible.
A few principles were recognized and specified later.
This document is partly based on a prior posting composed in reply to Ted Holden.