
Its similar to terrestrial animals. They die, sink to the bottom of the ocean and then get covered by layers of sediment like mud and sand. There is not a lot of oxygen under water which also helps the remains decompose slower which gives chance to the sediment to stick to the remains. Think about it like dropping a lollipop on the ground and having stuff stick to it. This happens overtime which hardens the remains thus making a fossil