According to the Oxford University Museum of Natural History, petrified fossils form when mineral deposits replace the bones of dead creatures inside hardened sediment. Over time, these deposits completely replace the remains, forming an image of the bones out of solid rock.
A fossil begins when an animal dies in conditions that allow its remains to be covered over before dissolving or scattering. At first, the sediment around the corpse is soft. Decomposers strip away the flesh and soft parts of the carcass, leaving only bones. The sediment molds around these bones, and pressure and heat converts the soft sediment into hard rock, completely encasing the remains.
Eventually, ground water works its way into the sediment, gradually dissolving the calcium of the bones. If the water contains enough minerals in suspension, it leaves deposits of these minerals. The bones disappear, gradually replacing the bones with much harder materials. This creates a fossil with all the external characteristics of the replaced bones, but none of the internal structure.
In addition to animal carcasses, fossils can also be created out of plants or even the footprints of long-ago beasts. In some cases, specific conditions like low oxygen or high acidity can preserve more of a fallen plant or prevent an animal from fully decaying. This preserves flesh or softer tissues as well as bones.