Fossils are formed in many different ways, but most are formed when a plant or animal dies in a watery environment.
Then the organism is buried in mud and dirt. Skin and organs quickly decay leaving the hard bones or shells behind. Over time, layers of rock builds over the top and hardens into rock. (Scienceveiws.com)