Sedimentary carbonates are very often formed thanks to the biological activity within the oceans. Rainwater percolates the continental rocks and dissolves a variety of ions, like calcium ions, contained in calcic feldspars for instance.
On the other hand, carbon dioxide was very abundant in the first ages of the planet Earth. Carbon dioxide dissolves in water in the form of bicarbonate and carbonate ions. Living organisms can fix these ions and produce calcium carbonate within shells.
After billion years of these mechanisms, very important layers of calcium carbonates are formed. With progressive burial of those sediments, these microcrystalline carbonates recombine gradually and form increasingly larger crystals. Exceptionally, centimetric and gemmeous crystals can be formed.