Limestone comes from either the accumulation of organic debris of shells, fecal matter, algae and corals or from dissolved calcium carbonate depositing on the seafloor. It is primarily made of calcium carbonate in the form of the mineral, calcite. Limestone generally forms in clear, warm, shallow marine environments.
Limestone sometimes forms in fresh water, and it also forms in caves by evaporation. When water evaporates, any calcium carbonate dissolved in it is deposited at the site. If the water evaporates on the ceiling of a cave, it gradually forms stalactites, whereas it forms stalagmites if it falls to the floor first.