Fossils are, as mentioned, imprints in sediment, or preserved bone, etc, left behind by something that died.
The sediments are in layers, much like tree rings. Some layers are deep/thick, and some are shallow/thin, etc.
The way the sediment settles, over time, is fairly well understood.
For example, if there were a nuclear accident or event, with fallout...and the radioactive dust settled on the ground or in the water, and sifted down to the bottom.
So, lets say were are in Nevada, where they tested atomic bombs...
We dig a hole, and use a geiger counter to see how deep that radioactive dust was...and, lets say its 1" down, covered by the dust that blows over that area.
So, we find a layer 1" down that shows where the blast's dust settled.
We know that anything UNDER that layer was settled there before the blast, and anything on top of that layer settled on top of it, after it was already there.
Take something that happened longer ago, say a massive volcanic eruption that was recorded at the time it occurred, so we have its location and date.
That will produce a layer of volcanic ash.
We then know everything that landed on that ash, landed after that date, and, that the earth under the ash layer is older than the ash layer that landed on it.
We can count tree rings. Trees grow in very defined and predictable ways, and, each ring represents one season/year.
If we have a bristle cone pine, and it has 12,000 rings, its 12,000 years old...and so forth.
Carbon, potassium, uranium, and other isotopes, minerals and elements, break down over time, and form new materials.
Uranium eventually becomes lead for example. It has a known half life, so, we can tell how long its been there...by how far along the process it is.
And so forth.
The earths magnetic field (Why we have the aura borealis, etc), flips every so many thousand years, so north becomes south and visa versa.
The iron in a rock will be aligned with what was north/south when the rock formed.
We know about tectonic plates (Job security for Vin Diesel/The Rock, etc, why the fault line by California is a fault line, etc...), and that the plates move in a known path, at known rates...and that Locke Ness and the east coast of the USA for example, used to be connected.
We know when two plates collide, and pitch up like a buckled floor board, we get mountains, and, the rocks the mountains are made up used to be under the ocean, so the previously horizontal layers of sediment, are now tilted even straight up vertically....
...and that two plate's now vertical/tilted layers can be pressed against each other...and we can tell how they got that way, and how they used to be.
Essentially, we have a massive list of ways to tell how old a rock is, or a tree, or a fossil.
Some are harder to tell, because the fossil might not have well preserved DNA, or minerals leached out, or there are contaminants of concern.
Just as a mathematician can make a mistake on a calculation, and forget to carry the one, it doesn't mean math is not valid.
Some people have had fossils analyzed inappropriately, such as when a creationist insists a varnished bone be carbon dated, and then gleefully reports that its age was misreported.
The nice thing about science is that it requires verification. Another scientist must be able to reproduce your findings to verify you didn't make a mistake/forgot to carry the one, etc.
So, what we find, using everything we know about fossils and geology, is that things in deeper layers, layers that are covered by newer layers, contain things that were deposited there longer ago.
The newer layers have things in them deposited on top of the older layers.
We do not find new layers that somehow snuck beneath the older layers.
In places where the layers are thin, and an inch might represent a million years or more, etc...things deposited millions of years apart could be within inches of each other in depth.
In places where the sediment settled more quickly, millions of years could be in meters not inches, and so forth.
So, humans and chimps, such as Bonobos, evolved from common ancestors. We did not evolve from them...we just share some great great, etc, grand parents.
There were many early human-like ancestors. Some, like the Neanderthal, and Denisovans, were around when Homo sapiens was too, and, we breed with them...and almost all Europeans have some Neanderthal DNA in them. A smaller number have Denisovan DNA, and so forth.
No Africans from Africa do. Some Chinese and other asian people do have Neanderthal/Denisovan DNA too though...etc, mostly because the Europeans breed like Bonobos....and some migration routes overlapped.
Modern humans have been around for a very long time...at least 100,000 years, with agriculture, etc, being evident as recently as the past 10-20,000 years.
Given our proclivity to breed with anything we can, the most likely scenarios all involve hybridization of the various proto-humans....into what we now call homosapiens.
So, when we find a Neanderthal fossil, it could be a distant relative unless you are an African with no dilution, etc. There's good chance otherwise, that the fossil and one of your ancestors made you who you are today.
:D