Limestone forms primarily in marine environments through the accumulation of shell, coral, algal, and fecal debris. It can also form through the precipitation of calcium carbonate from lake or ocean water. Its composition can vary, but it is predominantly made up of calcite and aragonite, which are different crystal forms of calcium carbonate.