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.
Related: the G-Code Cheat Sheet and the Unit Conversion Calculator.
