Limestone forms primarily from calcium carbonate in marine environments. It most commonly forms in warm, shallow seas where calcium carbonate from shells and skeletons of marine organisms accumulates over time and lithifies into sedimentary rock. Limestone can also form through chemical precipitation of calcium carbonate in ocean or lake water, or through evaporation in cave systems, leaving behind deposits like stalactites and stalagmites. Overall, limestone forms through either biological or chemical processes involving calcium carbonate in various marine and coastal environments.