---
title: "G20 vs G21: Inch vs Metric in G-Code, Explained"
description: "G20 tells the control to read the program in inches and G21 in millimeters. Here is the difference, why the wrong one is dangerous, and how to keep them straight."
url: https://gcodepractice.com/journal/g20-vs-g21-inch-vs-metric/
canonical: https://gcodepractice.com/journal/g20-vs-g21-inch-vs-metric/
author: "Lawrence Arya"
authorUrl: https://www.linkedin.com/in/vibecoding/
published: 2026-06-04
updated: 2026-06-04
category: "Code reference"
tags: ["g-code", "g20", "g21", "units", "beginner"]
lang: en
---

# G20 vs G21: Inch vs Metric in G-Code, Explained

> **TL;DR** G20 sets inch units and G21 sets millimeter units. They are modal, so whichever is active applies to every coordinate and feedrate until changed. The real danger is a units mismatch: run a metric program in inch mode and every move scales by 25.4, which causes overtravel and crashes. Always set the unit code explicitly at the top of the program.

`G20` and `G21` are the units codes. They tell the control how to read every number that follows: as inches or as millimeters. They look harmless on the page, but getting them wrong is one of the fastest ways to crash a machine, because every move scales by the wrong factor.

## G20: inch mode

`G20` puts the control in **inch** units. After it, `X1.5` means 1.5 inches, and a feedrate of `F10` means 10 inches per minute. Inch programming is common in US shops working from imperial drawings.

## G21: millimeter mode

`G21` puts the control in **millimeter** units. After it, `X1.5` means 1.5 mm, and `F10` means 10 mm per minute. Metric is the default almost everywhere else and on most modern controls. Both codes are documented in the [LinuxCNC G-code reference](https://linuxcnc.org/docs/html/gcode/g-code.html) and on the standard [G-code units pages](https://www.helmancnc.com/g20-g21-g-code-for-units-inch-metric/).

## They are modal, and they set the scale for everything

`G20` and `G21` are **modal**: they belong to the same group, only one is active at a time, and whichever you set stays active until you change it. The active unit applies to coordinates, feedrates, and many offsets, not just one line. This is the same modal behavior behind [G90 vs G91](/journal/g90-vs-g91-crash-prevention/) and the other setup codes you carry down the page, which is why tracking active modes matters when you [read a CNC program](/journal/how-to-read-a-cnc-program-for-beginners/).

## G20 vs G21 at a glance

| Aspect | `G20` (inch) | `G21` (metric) |
| --- | --- | --- |
| Unit of measure | inches | millimeters |
| `X1.5` means | 1.5 inches | 1.5 mm |
| `F10` means | 10 in/min | 10 mm/min |
| Common where | US imperial shops | most of the world |
| Modal group | units | units |

## Why the wrong units code is dangerous

The risk is a **units mismatch** between the program and the active mode. One inch equals 25.4 millimeters, so the scale error is large:

| You wrote | Active mode | Machine reads it as |
| --- | --- | --- |
| `X25.` (meant 25 mm) | `G20` inch | 25 inches (635 mm) |
| `X1.0` (meant 1 inch) | `G21` metric | 1 mm |
| `F200` (meant 200 mm/min) | `G20` inch | 200 in/min |

A metric move read as inches is about 25 times too far, which trips overtravel alarms or drives the tool straight into the part or fixture. Because of this, the standard [G-code conventions](https://en.wikipedia.org/wiki/G-code) treat the unit code as a safety line, not an afterthought.

## The machine has a default unit too

Every control powers up in a default unit set by a parameter, and the program's `G20` or `G21` overrides it for that run. That is exactly why you cannot trust the default: a shop standardized on metric can still receive an inch program, and the only reliable signal is the unit code written in the file. Switching units partway through a program is legal but rarely wise, because work offsets and the active coordinate system are then read in a new scale, which is easy to misjudge. Set the unit once at the top and leave it.

## How to keep them straight

The fix is a habit, not a trick: **set the unit code explicitly at the top of every program**, in the safety block alongside the plane and positioning modes (for example `G21 G17 G40 G90`). Never rely on whatever mode the last operator left active. On the page, the only difference is the last digit, so this pair belongs on any list of [common G-codes for CNC beginners](/journal/common-g-codes-for-cnc-beginners/) and is worth drilling until the right answer is instant.

## Bottom line

`G20` is inches, `G21` is millimeters. They are modal and they scale every coordinate and feedrate, so a mismatch between the program and the active mode is a 25.4x error and a real crash risk. Set the unit code at the top of every program and drill the pair until you never hesitate.

## Sources

- [LinuxCNC G-code reference (G20, G21 units)](https://linuxcnc.org/docs/html/gcode/g-code.html)
- [Wikipedia: G-code](https://en.wikipedia.org/wiki/G-code)
- [HelmanCNC: G20 G21 units inch and metric](https://www.helmancnc.com/g20-g21-g-code-for-units-inch-metric/)

## Frequently asked questions

### What is the difference between G20 and G21?
`G20` puts the control in inch mode and `G21` puts it in millimeter mode. They are modal codes in the same group, so only one is active at a time and it stays active until you switch it.

### What happens if you use the wrong units code?
The numbers get read at the wrong scale. A metric program run in inch mode treats every millimeter value as an inch, so moves are 25.4 times too large, which causes overtravel or a crash.

### Does G20 or G21 change the feedrate too?
Yes. The active unit applies to the `F` word, so under `G20` an `F` of 10 is 10 inches per minute and under `G21` it is 10 millimeters per minute.

### What is the best way to memorize G20 vs G21?
Drill the pair with active recall. A free app like G-Code Sprint shows `G20` and `G21` as side-by-side timed questions and repeats whichever you keep missing, so inch versus metric becomes automatic.

*G-Code Sprint is a study and practice tool only. Always follow your instructor, employer, machine manual, and shop safety procedures.*

---

Source: https://gcodepractice.com/journal/g20-vs-g21-inch-vs-metric/
Author: Lawrence Arya — https://www.linkedin.com/in/vibecoding/
