What G20 / G21 means
Unit selection is modal: once a controller accepts G20 or G21, later numeric coordinates are interpreted in that unit until another unit command changes the mode. Most 3D-printer slicers emit metric G-code, while CNC programs are more likely to use either system.
The command can affect axis coordinates, arc values and feed rates. Extrusion-unit behavior is firmware-specific, so a generic converter should not blindly multiply every number after G20. A reliable viewer must maintain the active unit state while reading the file and normalize geometry into one internal unit.
Syntax and parameters
G20 ; use inchesG21 ; use millimetersNo parametersThe command changes the modal unit state for subsequent blocks.
Practical examples
One-inch move
G20
G1 X1.0 F60Moves one inch at 60 inches per minute on controllers that apply G20 to feed rate.
Equivalent metric move
G21
G1 X25.4 F1524Represents the same nominal distance and speed in millimeters.
Firmware context
| System | Status | What changes |
|---|---|---|
| Marlin | Check dialect | Available only when inch mode is enabled in the firmware build; G21 is the normal printer default. |
| Klipper | Check dialect | Typical printer workflows are metric; verify macro and command compatibility before sending inch-mode files. |
| RepRapFirmware | Common | Supports standard unit selection with firmware-defined details. |
| CNC controllers | Common | G20/G21 are standard modal unit commands, but program defaults and affected words vary. |
What this viewer can show
The viewer reads both unit modes. Inch coordinates and movement speeds are converted to millimeters before the path is drawn.
Common mistakes
- Do not infer units from the file extension; inspect the actual modal command and controller defaults.
- A missing G20/G21 leaves interpretation dependent on the machine's starting state.
- Changing units mid-file is valid on some controllers but makes manual review and editing much harder.
Primary sources
This page is an original explanation, reviewed against the firmware documentation below. Always confirm commands against the firmware and configuration on the machine that will execute them.