G20 and G21: Inch and Metric Units

G20 makes the numbers in a program inches; G21 makes them millimetres. Every program should set one before its first move.

G20 sets inch units. G21 sets millimetre units. They decide how the machine reads every number in the program that follows: the X, Y and Z positions, arc centers and radii, and the F feed rate.

G20 G21
Units Inches Millimetres
X1 means 1 inch (25.4 mm) 1 mm
F is in Inches per minute Millimetres per minute

Both are modal. They usually go on the first line or two of the program, together with other setup codes such as G17, G90 and G54.

Why the wrong units are dangerous

If a program doesn't say which units it uses, the machine uses whatever it's already in: its power-up default, or the units left by the last program. A mismatch scales every move by 25.4:

  • A metric program run in inches is 25.4 times too big. G0 Z10 sends the tool 10 inches up, and G1 X50 tries to move 50 inches. On most machines that hits a limit or crashes.
  • An inch program run in millimetres is 25.4 times too small. The tool may cut a tiny part, or plunge where it should be clearing the stock.

The feed rate is scaled too, so the cut is also much faster or slower than intended. Setting G20 or G21 at the top of every program avoids all of this.

Example: a rectangle in inches

The program cuts a 2 × 1.5 inch rectangle 0.04 inches deep. Because of G20, every number is in inches, including the feed rates of 8 and 24 inches per minute.

(G20 and G21 example: a 2 x 1.5 inch rectangle in inch units)
(G20 makes every number below inches, including the feed rate)
G20 G17 G90 G54
T1 M6 (1/4 inch flat end mill)
S12000 M3
G0 Z0.5
G0 X0 Y0
G0 Z0.1
G1 Z-0.04 F8
G1 X2 F24
Y1.5
X0
Y0
G0 Z0.5
M5
M30
Open this example in CutViewer

Open it in CutViewer and the Job panel shows the part size and feed rates.

Line by line:

  • G20 G17 G90 G54 sets inches on the first line, before any move.
  • G0 Z0.5 rapids to half an inch above the part. Read as millimetres, it would be just 0.5 mm.
  • G1 Z-0.04 F8 plunges about 1 mm deep at 8 inches per minute (about 200 mm/min).

How CutViewer shows G20 and G21

CutViewer reads G20 and G21 and uses them for the program's units. If there's no G20 or G21 before the first move, the pre-flight checks warn that units are assumed to be millimetres, so you can add the right code before the program reaches the machine.

Frequently Asked Questions

Is G20 inches or millimetres?

G20 is inches and G21 is millimetres. An easy way to remember it is that the bigger unit, inches, has the smaller number.

What happens if a program has no G20 or G21?

The machine uses whatever units it's already in, from its power-up default or the last program that ran. If that doesn't match the program, every move is the wrong size, so always set the units at the start.

Does G20 or G21 change the feed rate?

Yes. With G20, F is in inches per minute; with G21, millimetres per minute. F600 is a sensible metric feed rate but 600 inches per minute is very fast.

Can I switch between G20 and G21 in the middle of a program?

Some controls allow it, but it's error-prone and many manuals advise against it. Set the units once at the start of the program and keep them.

Check your own program before you cut: open it in CutViewer to see the toolpath in 3D, the run time and any problems.

Open CutViewer