We use technical and security cookies and, only if you accept, analytics with no cross-site tracking. More in the Cookie policy and Privacy policy.
We use first-party cookies and technical storage to make the site work, Google reCAPTCHA security technology and, only if you accept, Vercel analytics (no cookies, no cross-site tracking). You can accept or reject analytics; both options are equivalent and you can change your choice at any time. More info: Cookie policy, Privacy policy, Legal notice and Terms and conditions.
G21 declares that the program coordinates are in millimeters and G20 that they are in inches. On their own they convert nothing: they only tell the control how to read the numbers that come after, and that includes the coordinates, the F feedrate, the R plane of the cycles, the Q peck and how the offsets are read. That is why they are written in the safety block on the first line and never touched again: get the mode wrong and the scale of the whole job changes by a factor of 25.4.
For reference only: syntax changes with the control, the post-processor and the machine parameters. Check the official manual and run a simulation before cutting. Legal notice.
Family
Units
Machine
Milling, Turning, Mill-turn
Risk
High
Example
G21 G90 G54
Syntax by control
Fanuc
G21G17G40G49G80
The change of units has to be made at the start of the program, in a safe block and with the modals clean; many controls forbid it anywhere else. Which system is active at power up is set by a machine parameter, not by the last program that ran.
Haas
G20/G21
On Haas the machine unit system is governed by Setting 9, which controls the offset screen and the panel feedrates. The G20 or G21 in the program works mostly as a check: if it does not match the setting, the control warns you. Changing the setting does not by itself convert the offsets already stored.
Siemens 840D / 828D
G71(mm)/G70(pulgadas)
Here is one of the most dangerous mix-ups between controls: on Siemens the units are G70 and G71, and G700/G710 do the same thing while also affecting feedrates and offsets. On Fanuc lathes, though, G70 and G71 are the finishing and roughing cycles. Same number, completely different function.
Heidenhain TNC (Klartext)
BEGINPGMPIEZAMM
Heidenhain declares the units in the header, when the program is created, and not with a G function. MM programs and INCH programs can live on the same machine, and the control handles the conversion when they are called.
Address letters used with it
Letter
What it sets
Unit
No arguments
G20 and G21 are modal selectors and carry no letters. What changes is how everything else in the program is read.
modal, no units
X Y Z
They start being read in inches under G20 and in millimeters under G21. The same X1.0 is 25.4 mm of difference between the two modes.
mm or in
F
The feedrate changes units with them: mm/min or in/min under G94, mm/rev or in/rev under G95. It is the thing most often forgotten when converting a program by hand.
mm/min or in/min
R I J K Q
Every arc and canned cycle value follows the active mode: the R plane, the radius, the arc center and the G83 peck.
mm or in
Worked example
The same job written in both systems: first a program in millimeters with the right header, and then the same lines converted to inches. Side by side you can see what really changes when you switch mode, which is not only the coordinates but the feedrate and the safe height as well.
O0120(VERSION EN MILIMETROS)
( Program header. )
G21G17G40G49G80
( First line of the safety block: millimeters, XY plane and everything cancelled. It goes before any move and before any offset is called. )
G91G28Z0.
( Z to the reference point before the change. )
T1M06
( 10 mm cutter. )
G90G54G00X-15.Y0.
( X-15 is fifteen millimeters. That same block under G20 would be fifteen inches, 381 mm: the table would run to the end of travel in rapid. )
G43H01Z50.M03S3000
( Z50 is fifty millimeters of safe height. In inches it would be nearly four feet, outside the travel of the machine. )
G00Z2.M08
( Approach to two millimeters off the face. )
G01Z-3.F150
( F150 is 150 mm/min. That same F150 read in inches would be 150 in/min, that is 3810 mm/min: the cutter enters the material four times faster than planned. )
G01X95.F600
( Cutting pass at 600 mm/min. )
G00Z50.M09
( Retract and coolant off. )
G91G28Z0.M05
( Z to the reference point and spindle stop. )
G90M30
( End of the metric version. )
O0121(LA MISMA PIEZA EN PULGADAS)
( Second program, for a machine set up in inches. )
G20G17G40G49G80
( Inches. Everything that follows is read in that system. )
G90G54G00X-.5906Y0.
( The 15 mm become 0.5906 inches. Four decimals is the sensible habit: a tenth of a thousandth of an inch is 2.5 microns. )
G43H01Z1.9685M03S3000
( The 50 mm of safe height are 1.9685 inches. The rpm do not change: S does not depend on the unit system. )
G01Z-.1181F5.9
( The 3 mm of depth and the 150 mm/min converted: 0.1181 inches and 5.9 in/min. Convert the coordinates and forget the feedrate and the program runs at 25 times the speed. )
G01X3.7402F23.6
( The 95 mm of travel and the 600 mm/min already converted. )
Where it goes and why you do not touch it afterwards
The unit selector goes on the first useful line of the program, inside the safety block, before any move and before any offset is called. The reason is that the power up state depends on a machine parameter and on the previous program, so it cannot be assumed. Changing units halfway through a program is worse still: the modal values already set (the feedrate, the R plane of the active cycle, the peck) keep the same number but start meaning something else, and that is why most controls only allow the change at the start.
What happens to the offsets and the work offsets
The work offset and tool offset tables are stored in one particular unit system, and whether the control converts them when the mode changes depends on the model. That is where the real danger sits: a length offset of 0.5 read as inches is 12.7 mm of difference in depth. The sensible shop rule is that each machine works in one system, that every program and every offset on that machine is in that system, and that a program arriving in the other one is converted before it is loaded, tool data included.
How you spot the error
The symptom is always a factor of 25.4 or its inverse: a move that runs to the end of travel the moment it starts, a feedrate that is absurdly slow or violent, a ridiculous depth, or a part exactly 25.4 times bigger than it should be. If that is the ratio, look no further. There is also a formatting trap worth knowing: on many Fanucs, a coordinate written without a decimal point is read in the least increment of the control, so X10 is not ten millimeters but ten microns. Always writing the decimal point takes that problem off the table.
Mistakes that cost you a part (or a tool)
Loading a program with no unit header: it runs in whatever mode the previous job left, and the operator has no way of seeing that by reading the program.
Switching from G21 to G20 halfway through a program: the feedrate, the R plane and the peck already active keep their number and change meaning.
Assuming G20 or G21 convert the offsets and work offsets stored in the machine.
Writing coordinates with no decimal point on a Fanuc: X10 can be a hundredth of a millimeter instead of ten millimeters.
Mixing up the Siemens G70/G71 (units) with the Fanuc turning G70/G71 (finishing and roughing cycles).
Having the machine unit setting in one system and the program in the other, and trusting the numbers on the screen.
Converting the coordinates by hand and forgetting the feedrate, the R plane or the Q peck, which are the three values most often left behind.
Frequently Asked Questions (FAQ)
Which one is which, G20 or G21?
G20 is inches and G21 is millimeters. On Siemens the equivalent pair is G70 for inches and G71 for millimeters, and on Heidenhain the units are declared in the program header when it is created, with no G function at all.
What happens if I forget to write G21?
The program runs in whichever mode was active, which may be the one the previous job left behind. If it was inches, every coordinate is effectively multiplied by 25.4 and the first move heads for the end of travel at rapid speed. It is a cheap mistake to avoid and an expensive one to suffer.
Does G21 convert the tool offsets?
Not necessarily: it depends on the control. The values in the tables are stored in one particular system and some machines convert them when the mode changes while others do not. The safe thing is to keep the whole machine, programs and tables included, in the same system.
Can I change units halfway through the program?
Technically some controls allow it, but it is a bad idea and many block it outside the start of the program. The modals already set are not reinterpreted and are left holding values that mean something else. If you need to work in both systems, write two programs.
What units does the feedrate end up in?
The ones of the active mode: millimeters per minute under G21 with G94 and inches per minute under G20 with G94, and the same per revolution if you work in G95. It is the value most often forgotten when converting a program, and the one that causes the loudest scares.