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.
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.
