In the most basic sense, compression ratio is the simply the volume of an engine's cylinder with the piston at the bottom (bottom dead centre, or BDC) divided by the cylinder volume with the piston at the top (top dead centre, or TDC). However, calculating compression ratio is nowhere near that simple in practice. An accurate compression ratio calculation must account for combustion chamber volume, head gasket thickness, piston deck height and piston domes or dishes.
Determine the swept volume (volume displaced by the moving piston) of one cylinder in centimetres. Formula: bore x bore x stroke x 0031416 = single cylinder swept volume.
Calculate the clearance volume, which is the distance from the top of the piston to the engine block deck surface. Formula: bore x bore x deck height (distance from the piston top to the deck in centimetres) x 0.1996 = clearance volume in CCs. A piston that's completely even with the block will have a deck volume of zero. Note pop-up pistons (where the piston pops up over the block deck surface) as a "negative volume."
Obtain the manufacturer's specs regarding your cylinder head's combustion chamber volume in CCs, the head gasket's compressed volume in CCs, and the displacement of the piston's dish/valve reliefs or dome in CCs. For our purposes, you'll consider a dish or valve relief as a regular "positive" CC measurement, and a dome as a "negative" CC measurement (as a dome removes volume from the chamber).
Add your derived figures up to get cylinder volume with the piston at TDC. Formula: combustion chamber volume + gasket compressed volume + clearance volume (MINUS clearance volume for pop-up pistons) + dish/valve relief volume (MINUS volume for a domed piston) = Chamber Volume at Top Dead Center, or CV-TDC. Add CV-TDC to your Swept Volume to derive Cylinder Volume at Bottom Dead Center, or CV-BDC.
Divide CV-BDC by CV-TDC to arrive at your final compression ratio.
It's good to know how this formula works in case you need to calculate CR on the fly, but you might want to consider bookmarking one of the handy compression ratio calculators in the Resources section below.