A Tyrannosaurus is walks along the shoreline, unaware of its fate.
Unfortunately, the Tyrannosaurus suddenly dies.
After a while, scavengers, other organisms, and decomposers like fungi and bacteria decompose the Tyrannosaurus. All the soft parts are gone, and they are replaced with the skeleton.
Over time, water covers up the skeleton and the land around it.
The bones sink to the bottom and is buried under layers of mud. Over millions of years, the mud is turned into sediment, and the fillings inside the bones are replaced by minerals and stone. This process is called petrification.
Eventually, the sediment rises, and erosion reveals the fossil. Paleontologists come to excavate it.