It a bit of a process! So when something dies it get buried in sediment which then turns to rock. So we assume that the rock/sediment is the same age as the fossil.
Often these rocks have special minerals inside them the record how old the rock is. These special minerals are radioactive! The key idea is that radioactivity goes away over time. So the older the rock is the less radioactive it is. We can use some principles in physics (radioactive decay) to work out how old the rock if we carefully measure the products of the radioactivity.
To measure these products we have to use a complicated chemistry procedure to extract and measure how many radioactive particles there are.