G20 sets your CNC machine to inch mode. Once active, every coordinate, feed rate, and offset value in the program is read as inches.
If you’re working from an inch drawing — or running a program written in inches — G20 needs to be active.
Key Takeaways
- G20 switches the CNC to inch mode — all values are interpreted as inches
- It’s a modal command, so it stays active until you switch to G21 (metric mode)
- There’s no cancel command — either G20 or G21 must always be active
- Place G20 in your safety line at the start of every program that uses inch values
- Never switch between G20 and G21 mid-program
| G21 – At A Glance | |
|---|---|
| Function | Set inch mode |
| Type | Modal (Group 6) |
| Cancelled by | G21 (switches to metric mode) |
| Used with | Any program using inch dimensions |
What Does G20 Do?
A G20 code switches the CNC into inch mode.
G20 tells the CNC to read all values in inches. That includes X, Y, and Z coordinates, feed rates, offsets, and any other numerical input in the program.
This is called a modal command. Modal means it stays active on its own — you don’t have to repeat it on every line. It stays in effect until something cancels or changes it.
One thing that trips up beginners: G20 stays active even if you restart the program or the machine loses power and restarts. The last active unit mode is remembered. That’s why safety lines exist.
G20 vs G21: Inch Mode vs Metric Mode
G21 is the other unit mode. When G21 is active, the machine reads all values as millimeters. When G20 is active, it reads inches.
These two codes are a pair. You can’t cancel either one — you can only switch between them. One of them must always be active.
Do not switch between G20 and G21 in the middle of a program. If a program starts in inches, keep it in inches throughout. Mixing units causes calculation errors and can crash the machine.
Where to Put G20 in Your Program
Most machinists place G20 (or G21) in the safety line at the very start of the program, along with other setup codes like G90 and G54.
Here’s what a typical safety line looks like in an inch program:
G20 G90 G40 G49 G80 (Safety line: inch mode, absolute, cancel comp/cycles)
G54 (Select work coordinate system)
G00 X0. Y0. (Rapid to starting position)
Placing G20 here makes sure the machine is always in the right mode — even if someone ran a metric program before yours.
You can also place G20 at the start of a specific section of code if that section uses inch values. But as a rule, avoid mixing units in the same program.
⇄ Inches / Millimeters Converter
Common values
| 1 in | = 25.4 mm |
| 0.5 in | = 12.7 mm |
| 0.25 in | = 6.35 mm |
| 0.125 in | = 3.175 mm |
| 0.001 in | = 0.0254 mm |
What to think about when using a G20 code?
When you use a G20 code you simply need to be aware of what type of units you are working in.
Most machine shops will work in only one unit mode, either inches or mm.
There are definitely some shops out there that will use mixed units, but in most cases CNC programs will be written in one or the other for every program they make.
Know whether your parts are in inches or mms.
What to Watch Out For
Know what units your part drawing uses. Most shops work in one system — either inches or millimeters — and stick to it for every program they run.
If you’re not sure whether G20 or G21 is currently active, check the active modal codes on the control. Most controls show the current unit mode on the main status screen.
COMMON MISTAKE – Running an Inch Program in Metric Mode
Running an inch program on a machine that’s still set to G21 (metric mode). A 1.0″ move becomes a 1mm move — the machine will run the program, but your parts will come out completely wrong.
Always verify your unit mode before hitting cycle start.
FAQS
Does G20 reset when I turn off the machine?
It depends on the control. Most modern CNC controls remember the last active unit mode after a power cycle. That’s exactly why you should always include G20 (or G21) in your program’s safety line — so you’re never depending on whatever mode was left over from the last operator.
Can I switch from G21 to G20 in the middle of a program?
Technically yes, but you should avoid it. Switching unit modes mid-program is a serious source of errors and is not recommended on most controls. Keep your programs consistent — all inches or all metric.
What happens to feed rates when G20 is active?
Feed rates are also interpreted in the active unit mode. In G20, a feed rate of F10 means 10 inches/min. In G21, F250 means 250 mm/min. This is another reason not to mix modes in a single program.
Is G20 the same on all CNC controls?
G20 for inch mode is standard across most Fanuc-based and Fanuc-compatible controls. Some older or less common controls may handle unit modes differently — always check your control’s programming manual if you’re unsure.