G20 G21 Units

G20 and G21 set the measurement units for the whole program. Getting this wrong is one of the most dangerous mistakes in CNC — a program written in inches but run in millimeters moves 25 times too far.

Code Units
G20 Inch
G21 Millimeter

Place the units code in the safety line at the very top of the program so there is no ambiguity, and confirm it matches the dimensions and feed rates you programmed.

G20 G17 G40 G90 (typical safety / startup line)

FAQ

What happens if I run a metric program with G20 active by mistake? Every coordinate and feed value gets interpreted in inches instead of millimeters, scaling all moves by roughly 25 times. This can cause a large, unexpected crash, so checking the units mode is one of the first things to verify before running an unfamiliar program.

Does switching between G20 and G21 mid-program cause problems? It can, if any coordinates or offsets were entered in the other unit system before switching, since the control reinterprets all following values in the new units without converting previously stored positions.

Related: the G-Code Cheat Sheet and the Unit Conversion Calculator.

Scroll to Top

The calculators and tools on Formula Factory are provided for general guidance and informational purposes only. Results are estimates based on standard formulas and the values you enter — they do not constitute professional engineering, electrical, or architectural advice. Always verify calculations with a qualified professional before making decisions for any safety-critical, code-compliance, or commercial application. Formula Factory makes no representations or warranties as to the accuracy or completeness of any result, and accepts no liability for errors, omissions, or any outcomes arising from reliance on this information.