CNC mill · G-code

G20 / G21: inch and metric units

G20 means the program is in inches and G21 in millimeters. Haas lists it in modal group 06. On a Haas they don’t switch units: Setting 9 does, and G20 alarms if Setting 9 isn’t inch. On LinuxCNC they set the units. Formats below from Haas and LinuxCNC, each from its maker.

Worked example

State the units in the safe start line. Written for this page in the Haas format.

%O01000 (inch program)G20 G17 G40 G80 G90 G94 (on a Haas, alarms here if Setting 9 is MM)

How each control writes it

Haas G20 / G21

One source: Haas Automation, the control's maker

  • Setting 9 selects inch or metric programming; G20 and G21 make sure it matches the program.
  • G20 in a program alarms if Setting 9 is not set to inch.

Source: Haas Automation, mill G20

LinuxCNC G20 / G21

One source: the LinuxCNC project, the control's maker

  • G20 sets inch length units, G21 millimeters.
  • Put the units in the preamble of every file.

Source: LinuxCNC documentation, "G20, G21 Units" (archived Oct 29, 2026)

No Fanuc row yet: that chapter of the 0i manual has not been read.

Haas follows Fanuc's numbering, but options and parameters differ between controls: check your control's manual.