Living things are made up of chemical compounds, most of which are organic compounds. Organic compounds consist mainly of carbon, oxygen, and hydrogen. After a plant or animal dies, it decomposes. As organisms decompose, their organic compounds change into simpler compounds like carbon dioxide and water. Decomposition is fastest when the organisms are in water that contains dissolved oxygen. Organisms can also decompose even without oxygen. Some kinds of bacteria feed on plant and animal tissues even though there is no oxygen. These are called anaerobic ("no air") bacteria. Sooner or later, almost all organic matter from plants and animals decays. Decay slows down only when the organic matter is buried in very fine mud. That seals the organic matter off from water with oxygen.
The soft parts of an organism decompose the fastest. You know how little time it takes for food to spoil and rot in warm weather when it is not in the refrigerator. Bones and shells decompose much more slowly. Over long times, their mineral materials dissolve. That can happen rapidly when the shells and bones lie on the ground surface or on the sea bottom. If the shell or bone is buried in sediment, it dissolves more slowly. Shells are preserved without being dissolved only when they are buried in sediments that consist of calcium carbonate minerals, like limestones. The woody parts of plants that consist mostly of cellulose and lignin decompose much more slowly than the softer parts.
Most animals become fossilized by being buried in sediment. For them to be fossilized, they have to be buried and leave an imprint before they decompose. Animals without skeletons are seldom fossilized, because they decompose so quickly. Animals with hard skeletons are much easier to fossilize. The most common fossils are shells of marine animals like clams, snails, or corals. Insects, with thin outside skeletons of chitin, are not as easy to fossilize. Sometimes an insect is trapped in sticky material, resin, which comes out of some kinds of trees. The resin then hardens to a material called amber. The insect fossil is preserved in the amber, often perfectly.
Sometimes the actual shell or bone is preserved. Usually, however, you see only its imprint. If it resists being dissolved for a long enough time, the sediment around it turns into rock. Then, even though the shell or bone dissolves, the imprint is preserved. When a hammer splits the rock open, the fracture might pass through the imprint, and you see a fossil.