The formula
CR = (swept volume + clearance volume) ÷ clearance volume. Swept volume is one cylinder's displacement. Clearance volume is everything left when the piston is at the top: the combustion chamber in the head, the head gasket's thickness times its bore area, the gap between the piston and the top of the block, and any dish in the piston (a dome subtracts).
Compression and boost
Higher compression makes more power and better economy, but brings the engine closer to knock. Turbo builds often lower compression with a thicker head gasket or dished pistons so they can run more boost on pump fuel. On a 1.6 NA Miata, a head gasket 0.5 mm thicker takes compression from 9.4 to about 9.0. Try it above.
Static vs dynamic compression
This calculator gives static compression, the geometric number. Dynamic compression also accounts for when the intake valve closes, which depends on the camshaft. Two engines with the same static ratio can behave very differently with different cams.