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)

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.