The formula is easy. In practice it becomes a little more difficult. Also, most given compression ratios are a static compression ratio (CR). There is a dynamic CR, but that's a discussion I'll leave for a different question. You also ask how they calculate the CR ratio theoretically & practically ... well, it doesn't really matter, because the math works the same either way.
The compression ratio (CR) is the ratio when comparing the volume of the cylinder above the piston when the piston is at BDC as opposed to when the piston is at TDC. The measurements which are needed to figure these things out includes:
- Cylinder bore diameter
- Crankshaft stroke length
- Head gasket bore diameter
- Head gasket compressed thickness
- Combustion chamber volume
- Piston dome volume
- Piston deck clearance volume
You use the cylinder bore diameter and the crankshaft stroke length to figure out the swept volume of a single cylinder. You need the head gasket bore diameter, which may be slightly different from the cylinder bore diameter, and the head gasket compressed thickness to account for the space between the deck and the cylinder head. The piston dome volume is considered either positive or negative. This is usually provided by a piston manufacturer to help aid in figuring out the CR. The piston deck clearance volume is the distance between the top of the piston at TDC and the top of the deck.
Once you have the numbers, figuring the CR is fairly basic math. Add up all the volumes besides the displacement. This number would be used in both sides of te equation. Once that is added up, add the number to the total displacement, then divide this by the first number.
Clearance Volume = Head gasket volume + combustion chamber volume + piston dome volume + piston deck clearance volume
Swept volume = cylinder displacement
To spell it out a little better:
- (swept volume + clearance volume) / clearance volume
The number calculated is the static compression ratio, expressed as CR#:1
Obviously, the stricter you are when calculating the separate volumes the better the final value will be.
If you REALLY wanted to get technical about things, you'd also include the area from the top of the piston to the top of the piston ring. In practice, though, this area is so insignificant it won't make a difference unless you are in full race mode.
Here's a quote from MotorTrend.com:
“Too many people get hung up on tenths of a point in CR but fail to understand the effects of fluid dynamics due to appropriate cam selection and phasing, for example,” says Stevenson. “If everything else is well-matched, a difference in 0.1 of ratio is negligible for anything shy of maximum effort professional racing.”
As for the volume of the spark plug hole/spark plug, this is included in the combustion chamber volume. The way you measure the combustion chamber is with liquid. If the hole isn't plugged, the liquid would run out. What is the easiest thing to plug it with? A spark plug.
If you don't want to go through all the pain of figuring this out for yourself, you can do a search online for a compression ratio calculator. This will allow you to put in all of the raw measurement values and it will compute all of the volumes and produce a CR automagically.