G-code reference

G21: Metric units

G21 is metric units. Programs positions and feeds in millimetres. It is modal, so it stays active on the following lines until another code from the same group replaces it.

What G21 does

G21 makes the control read dimensions in millimetres and feeds in mm per minute or per revolution. Put it in the safety line at the start of the program so the unit never depends on what the last program left active.

TypeG-code
MachineMill and lathe
GroupUnits
ModalYes: stays active until replaced by another code from the same group

G21 example

G21

Everything after this is in millimetres.

WordWhat it means here
G21Metric units

Codes people confuse with G21

CodeWhat it does instead
G20 Inch units. Programs positions and feeds in inches.

Other codes in the units group

Only one code from a modal group is active at a time. Programming any of these replaces G21.

  • G20 Inch units

Meanings follow the common Fanuc-style standard that Haas, Okuma (EIA mode), Mitsubishi, LinuxCNC and most other controls share for this code. Options and parameters change details from machine to machine, so check the manual for your control.

Quick check: G21

  1. What does G21 do? (Mill and lathe)

  2. Which code: Programs positions and feeds in millimetres.(Mill and lathe)

  3. What does G20 do? (Mill and lathe)

Show the answers
  1. Programs positions and feeds in millimetres.
  2. G21
  3. Programs positions and feeds in inches.

Drill this code with the rest of the core set

More practice hubs

Frequently asked questions

What does G21 mean in CNC programming?
Metric units. Programs positions and feeds in millimetres.
Is G21 modal?
Yes. G21 belongs to the units group and stays active until another code from that group is programmed.
What is the difference between G21 and G20?
G21 (metric units): programs positions and feeds in millimetres. G20 (inch units): programs positions and feeds in inches.

G-Code Sprint is an educational practice tool only. It is not a CNC simulator, machine controller, safety manual, or replacement for instruction. Always follow your instructor, employer, machine manual, and shop procedures.

Free preview · no card Try G-Code Sprint