Limestone is primarily formed through the accumulation of marine organisms such as coral and shells, as well as through chemical precipitation in bodies of water. Over time, these organic and inorganic processes lead to the formation of limestone deposits.