The earth’s magnetic field affects the alignment of elements like iron in rocks due to Ferro-magnetization. This causes the elements to align in a north-south direction. Therefore scientists have studied this alignment in ancient rocks, such as in the layers of sedimentary rocks, and realized that the earth magnetic field has flipped around 200,000 to 300,000 in the last 20 million years.