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.
It Affects Feed Rate Too
Units don’t just change how position values are read — they also change how feed rate is interpreted. A feed word written for inches-per-minute means something very different if the control is in millimeter mode, so a units mismatch can combine with a feed error at the same time, not just a position error.
Many controls default to whichever units mode was active the last time the machine was used, rather than resetting to a fixed default on power-up. That’s exactly why a program written on one machine and run on another (or after a different operator used different units) needs its units line checked explicitly rather than assumed.
Running a program’s first moves in single-block mode with the machine’s travel limits in view is a good habit after any transfer between machines or controls — it catches a wrong units mode before it turns into a crash.
