Skip to main content
CNC.wikiCNC.wiki

G20 and G21 G-Code: Inch and Metric CNC Unit Selection Guide

Master G20 and G21 inch/metric unit selection on Fanuc, Siemens, and Mitsubishi CNC controls. Learn safety parameter settings, alarms, and G-code setup.

Hakan Gündoğdu
Hakan Gündoğdu

CNC CARE Co-founder

Introduction

A single unscaled G-code block can instantly transform a high-precision CNC machining center into a scene of mechanical devastation. When a programmer switches a machine's active measurement system between inches and millimeters without verifying that the control's offset memory, active workpiece coordinates, and technological feedrates have automatically converted, the machine blindly executes travel vectors based on mismatched mathematical scales. An operator who assumes imperial coordinates have been converted to metric dimensions may witness a cutting tool or indexable turret assembly plunge directly into a rotating chuck, a fixture, or a tailstock barrier. This severe tracking error triggers high-load structural alarms, shatters solid carbide tooling, deforms indexing turret components, and permanently converts expensive stock material into a completely ruined scrap part.

Technical Summary

SpecificationDetails
Command CodesG20 (Inch Input) / G21 (Metric Input) in Fanuc, Mitsubishi, and Siemens ISO Dialect. Native Siemens uses G70 / G700 (Inch) and G71 / G710 (Metric).
Modal GroupGroup 06, Modal (remains active until explicitly changed or overridden).
Supported BrandsFanuc, Siemens, Mitsubishi.
Critical ParametersFanuc: Parameter 5006 bit 0 (OIM), Parameter 14000 bit 2 (IRFx). Siemens: MD10240 $MN_SCALING_SYSTEM_IS_METRIC, MD10260 $MN_CONVERT_SCALING_SYSTEM. Mitsubishi: Parameter #1226 aux10/bit6, Parameter #1253 set25/bit1.
Main ConstraintRotary axes are locked to degrees and are completely unaffected by unit scaling commands. PLC-controlled axes ignore G20/G21 program changes and obey hardware-level configuration parameters only.

Quick Read

  • Always return all axes to the true machine reference position using G28 (especially on Fanuc) before executing a G20/G21 switch to prevent coordinate shift alarms like PS5362.
  • Explicitly define a new feedrate value (F-word) immediately after switching units, as standard G20/G21 commands do not automatically scale active feedrates.
  • Verify that automatic tool offset conversion parameters (such as Fanuc 5006 bit 0, Siemens MD10260, or Mitsubishi #1226) are enabled to prevent massive dimensional deviations.
  • Note that rotary axes coordinates are universally locked in degrees and remain completely unaffected by any inch or metric unit scaling commands.
  • Program legacy ISO Dialect unit commands standalone at the start of a block to prevent syntax errors and interpreter stops on Siemens controls (e.g., Alarm 15030).
  • Utilize dry run graphics and chuck/tailstock barriers (such as G22/G23 on Mitsubishi) to visually and logically validate machine coordinates before live cutting.

Basic Concepts

At the core of CNC coordinate tracking lies the G-code unit selection command, modal codes belonging to Group 06 that specify whether coordinate values are interpreted as inches (G20) or millimeters (G21). Changing these measurement systems completely redefines the mathematical scaling of length-related data, including programmed target positions, circular interpolation parameters (I, J, K), and programmable work coordinate systems. Establishing correct plane parameters is critical before applying coordinates, often requiring working plane selection prior to executing unit scaling. When a program executes a unit switch, the physical distance represented by a value of "1.0" shifts from 1 millimeter to 25.4 millimeters (or vice versa), making it the single most critical setup instruction in the NC file.

Legacy unit switch commands traditionally alter only geometric coordinate dimensions, leaving technological parameters like feedrate F and handwheel incremental jogging weights unscaled. If a programmer changes the active system of units mid-program without explicitly deactivating active tool radius compensations and writing a new F-word, the control misinterprets the scaling. This leads to coordinate deviations that can instantly trigger controller alarms, plunge the cutting tool into rotating workholding devices, and convert valuable workpieces into ruined scrap parts.

Command Structure

The structural implementation of G20 and G21 requires them to be programmed as standalone G-codes, generally at the absolute beginning of the program. Because these commands act as a global interpreter switch, they must not be combined with other movement coordinates or G-codes on the same block. A standalone block, such as G20; or G21; on a line by itself, ensures the interpreter registers the unit change before processing any movement instructions.

Depending on the brand's active language dialect, alternative codes may be utilized. For example, Siemens native mode uses G70 and G71 to scale geometric dimensions, or the extended G700 and G710 to scale both geometry and technology data simultaneously. Under certain configurations, Fanuc systems can also be programmed with G70 and G71 by adjusting specific parameter bits. When performing linear interpolation in a multi-unit program, specifying a new coordinate baseline ensures correct travel limits. Regardless of the syntax, these codes establish the baseline unit system for all linear axes, while rotary axes consistently maintain their native unit of degrees.

G20 ; (Inch Command Mode)
G21 ; (Metric Command Mode)

For Siemens native mode, the syntax expands to:

G70   ; (Siemens Native Geometric Inch Mode)
G71   ; (Siemens Native Geometric Metric Mode)
G700  ; (Siemens SW5+ Extended Inch Mode: scales geometry and feedrates)
G710  ; (Siemens SW5+ Extended Metric Mode: scales geometry and feedrates)

Brand Applications

Fanuc

Fanuc controllers manage unit selection through modal Group 06 commands G20 and G21. The system relies on deep parameter integration where Parameter 3402 bit 5 controls if standard G20/G21 or G70/G71 syntax is utilized, while Parameter 5006 bit 0 defines whether active tool offsets are automatically recalculated to prevent dimensional deviation. Attempting a changeover away from the reference point will cause the control to reject the unit switch and halt.

To safely perform a unit switch, Fanuc setups require a return to the reference position using G28, followed by the standalone command on a dedicated block, such as G20; or G21;.

CategoryDetails
Key ParametersParameter 3402#5 (G70), Parameter 11222#0 (NIM), Parameter 14000#2 (IRFx), Parameter 5006#0 (OIM)
Alarms & TriggersPS5362 (unit switch off reference position when 14000#2 is 1), PS1298 (switch during manual shift/mirror image when 11222#1 is 0), PS0092 (switch off reference position along all axes when 1015#0 is 1)
Version DifferencesMachining Center (M) and legacy Series 15-M configurations support alternative G70/G71 codes depending on Parameter 3402#5, whereas Lathe (T) models stick to standard G20/G21.

Warning: Programmers must ensure Parameter 5006 bit 0 (OIM) is enabled before executing G20/G21 switches; if disabled, tool offset data will not convert, resulting in unscaled tool offsets that will cause catastrophic dimensional errors during tool paths.

Siemens

Siemens controls leverage a multi-layered scaling system using standard ISO Dialect commands G20/G21 or native commands G70/G71 and G700/G710. The core basic measurement system is defined by machine data MD10240, while extended automatic scaling conversion of active work offsets and tool offsets is governed by MD10260.

In ISO dialect mode, G20 or G21 must be programmed at the start of a block and standalone. Native Siemens commands are integrated directly within travel blocks, such as N10 G700 X2.75 Y3.22 F10.0.

CategoryDetails
Key ParametersMD10240 $MN_SCALING_SYSTEM_IS_METRIC, MD10260 $MN_CONVERT_SCALING_SYSTEM, MD10250 $MN_SCALING_VALUE_INCH, MD10884 EXTERN_FLOATINGPOINT_PROG
Alarms & TriggersAlarm 4070 (scaling machine data altered manually), Alarm 15030 (active measurement system conflicts with incoming data block), Alarm 4240 (CPU overflow from excessive length-dependent user variables during switch), Alarm 61529 (basic system MD10240 mismatches programmed G command)
Version DifferencesSoftware version SW5 and later supports G700/G710 for simultaneous scaling of geometric and technological data (feedrates), whereas legacy SW1-SW4 versions do not support automatic scaling of technological data.

Warning: Changing the core scaling machine data manually without system conversion active will trigger Alarm 4070, indicating that existing background offset and compensation data have not been automatically scaled.

Mitsubishi

Mitsubishi CNC platforms process G20 and G21 dynamically across the envelope when Parameter #1226 aux10/bit6 is set to 1, converting the coordinate counter, user parameters, and active offsets. Additionally, shop administrators can lock out all unit changeover attempts by enabling Parameter #1253 set25/bit1, protecting the machine's base unit coordinate integrity.

The commands are programmed absolutely, either standalone or alongside compatible G-codes on a travel block, such as G21 G01 X150.0 Z50.0 F300.;.

CategoryDetails
Key ParametersParameter #1041 I_inch, Parameter #1226 aux10/bit6, Parameter #1152 I_G20, Parameter #1253 set25/bit1, Parameter #1042 pcinch
Alarms & TriggersP67 (changeover commanded without program unit switch option activated), P34 (format error triggered when mode switch is attempted while lockout parameter #1253 is active)
Version DifferencesNC axes obey program G20/G21 instructions, whereas PLC-controlled axes ignore them entirely and are governed solely by parameter #1042 pcinch. Rotary axes remain strictly locked in degrees across Machining Center (M) and Lathe (L) controls.

Warning: If Parameter #1226 is set to 0, G20/G21 will switch program coordinates but will fail to convert offsets, leading to a severe mismatch where unscaled metric tools are driven into imperial coordinate paths.

Brand Comparison

Topic / FeatureFanucSiemensMitsubishi
Primary Unit Selection G-codesG20 (Inch) / G21 (Metric)ISO Mode: G20 / G21
Siemens Mode: G70 / G71
G20 (Inch) / G21 (Metric)
Technological scaling (Feedrate F)Manual recalculation requiredExtended G700 / G710 codes scale feedrate automaticallyAutomatically scaled in active G20/G21 G94/G95 modes
Reference position restrictionsParameter 14000#2 can restrict G20/G21 exclusively to the reference position, throwing PS5362 alarm if violatedNo restriction; active coordinate offsets must be traced back or cleared before changeoverNo reference position restriction; changeover permitted anywhere in coordinate envelope if screen parameter #1226 is 1
Auto-scaling of Tool & Work OffsetsConfigurable via parameter 5006#0 (OIM)Configurable via parameter MD10260 $MN_CONVERT_SCALING_SYSTEM (SW5+)Configurable via parameter #1226 aux10/bit6
Switch Lockout / ProtectionLockable via standard coordinate safety parametersBlocks inconsistent blocks in data blocks via Alarm 15030Explicit lockout via parameter #1253 set25/bit1, triggering P34 alarm
PLC Axis Handling— (no source)Treated under standard machine dataPLC axes completely ignore program G20/G21; unit set via #1042 pcinch
Rotary Axis Scaling— (no source)Locked to degrees (not scaled)Locked to degrees (not scaled)

Technical Analysis

Analytically, the primary differences between the three major control systems lie in their approach to active state conversion and kinematic safety constraints. Fanuc adopts a highly conservative, parameter-locked safety philosophy. By utilizing parameter 14000#2, machine builders can restrict unit changes exclusively to the physical reference point, causing the control to instantly abort the switch and issue a PS5362 alarm if a change is commanded mid-program. Fanuc's standard coordinate conversion (G20/G21) requires explicit activation of parameter 5006#0 (OIM) to scale tool offset registers, meaning standard G-code executions do not guarantee automatic offset scaling unless pre-configured. In contrast, Mitsubishi offers a more dynamic on-the-fly approach. Through parameter #1226, Mitsubishi can execute unit switching anywhere within the work envelope and will automatically convert position counters, feedrates, and tool offsets. However, to maintain control, it integrates a dedicated administrative lockout parameter #1253 set25/bit1 that triggers a P34 alarm, preventing program-level unit changeovers entirely.

Siemens operates under a sophisticated, multi-layered architectural hierarchy that merges ISO dialect parsing with native NC settings. While standard ISO G20 and G21 only scale geometric dimensions, Siemens native G700 and G710 commands (available in software version SW5 and later) scale both geometry and technological parameters (such as feedrate F) in a single block. Siemens governs background compensation and work offsets via MD10260 $MN_CONVERT_SCALING_SYSTEM, which prevents unscaled movement coordinates. Unlike Fanuc and Mitsubishi, Siemens also provides the unique MD10884 EXTERN_FLOATINGPOINT_PROG parameter, allowing operators to dynamically toggle how coordinates without decimal points are interpreted—treating them either as standard internal units or calculator-style units (mm or inches)—offering unmatched legacy code parsing capabilities.

Program Examples

Fanuc G-Code Example

G28 U0 W0;                  ; Return to reference position (required on many Fanuc setups)
G20;                        ; Select Inch input
G00 X2.0 Z1.5;              ; Rapid movement in inches

dry run

During a dry run, the operator must verify that the turret first retracts to the physical machine reference coordinate system using G28 U0 W0. Once at reference, the control processes G20, shifting the interpreter scale so that the subsequent rapid command G00 X2.0 Z1.5 moves the tool precisely 2.0 inches in the X-axis and 1.5 inches in the Z-axis relative to the active coordinate system. The operator should observe the screen position counter change units and watch the tool path graphics to ensure no unscaled millimeter coordinates remain active.

Siemens G-Code Example

G291;                       ; Switch to ISO dialect mode
G20;                        ; Select Inch input
G290;                       ; Return to Siemens mode
N10 G700 X2.75 Y3.22 F10.0; ; Native Siemens Inch mode (G700 scaling coordinates and feedrate F)

dry run

During a dry run, the control first executes G291 to parse the legacy ISO unit selection command G20 standing alone in its block. Upon returning to native mode via G290, block N10 invokes the extended native command G700, which forces the control to interpret the coordinates X2.75 Y3.22 as inches and simultaneously converts the feedrate F10.0 to 10.0 inches per minute. The operator must check that both axis movements and feedrate velocities are scaled correctly on the diagnostic screen before initiating live machining.

Mitsubishi G-Code Example

G20;                        ; Switch program command unit to the inch system
G00 X5.0 Z2.0;              ; Rapid motion in inches
G21 G01 X150.0 Z50.0 F300.; ; Metric mode switch with linear interpolation in mm and feedrate in mm/min

dry run

During a dry run, the programmer verifies that G20 switches the interpreter unit scale to inches, prompting the G00 X5.0 Z2.0 rapid motion to drive the axes 5.0 inches in X and 2.0 inches in Z. The control then reads the next block, where G21 instantly shifts the modal state to metric, so that G01 X150.0 Z50.0 F300. interpolates linearly in millimeters (150.0 mm in X, 50.0 mm in Z) at a metric feedrate of 300 mm/min. The operator must watch for the sudden deceleration in feedrate and coordinate conversion on the position display.

Error Analysis

BrandAlarm CodeTrigger ConditionOperator SymptomRoot Cause / Fix
FanucPS5362Attempting G20/G21 unit switch away from reference position when 14000#2 is enabled.Machine halts immediately; screen displays "CONVERT INCH/MM AT REF-POS" alarm; axes movement stops.Root Cause: Axis is not positioned at the reference point.
Fix: Program G28 to return the tool to the reference position before executing the unit switch command.
FanucPS1298Commanding G20/G21 while workpiece coordinate system is shifted and 11222#1 is set to 0.Program execution aborts; screen shows "ILLEGAL INCH/METRIC CONVERSION" alarm.Root Cause: Active shift amounts from manual intervention, handle interrupt, or active mirror image are engaged.
Fix: Clear all manual shift amounts or set parameter 11222 bit 1 (CIM) to 1 to allow automatic system clearing.
FanucPS0092Switching units when the machine is not located at the reference position along all axes (parameter 1015#0 is 1).System generates a P/S alarm 92; CNC goes into alarm state, blocking all axis motion.Root Cause: The system requires all axes to be at reference before changing measuring systems.
Fix: Execute a complete manual or programmed reference position return along all axes prior to G20/G21 switch.
SiemensAlarm 15030Reading an INCH or METRIC instruction that conflicts with active control measurement settings.Interpreter stops execution immediately; cycle start is interrupted; screen displays measurement system mismatch.Root Cause: The active measurement system of the control and the incoming data block are misaligned.
Fix: Align the measurement system of the control and the read block or correct the programmed G-code.
SiemensAlarm 4070Manually altering the unit scaling machine data (like MD10260) or via file.Screen alerts with "Scaling machine data altered" warning; subsequent axes moves may execute with unscaled data.Root Cause: Machine data scaling system is changed without automatic offset recalculation enabled.
Fix: Perform a POWERON reset to activate the scaling and check all tool compensation/offset values manually.
SiemensAlarm 4240CPU time overflow when switching measuring systems with excessive length-dependent user variables.NCK interpreter overflows; system halts or experiences communication lag; screen displays format conversion error.Root Cause: Too many length-dependent user variables (GUD/PUD/LUD) are active in main run synchronized actions during switch.
Fix: Avoid or minimize the use of physical length-dependent user variables in main run synchronized actions.
MitsubishiP34Commanding G20 or G21 while lockout parameter #1253 set25/bit1 is set to 1.CNC triggers a P34 format error; mode switch is rejected; axes travel is blocked.Root Cause: Security lock on unit conversion is enabled to protect the machine coordinates.
Fix: Change lockout parameter #1253 bit 1 to 0 to permit unit changeover, or eliminate G20/G21 codes from the program.
MitsubishiP67Commanding G20/G21 on a control without the program unit changeover option activated.Alarm P67 "No spec" displays; program execution halts; machine remains in its basic unit state.Root Cause: The physical controller lacks the required program unit conversion software option.
Fix: Order and activate the option specification from Mitsubishi, or rewrite the G-code program in the machine's native unit system.

Application Note

A devastating hard collision occurs when a setup operator switches the active program units from G20 to G21 without verifying that parameter #1226 aux10/bit6 is active, driving an unscaled cutting tool directly into the rotating chuck. When #1226 is disabled, the control shifts the movement coordinates to metric millimeters but fails to convert the tool offset register, applying unscaled tool geometry and wear offsets to the coordinate path. To safeguard machine boundaries and protect structural components like the tailstock assembly and the indexing turret from impact damage, programmers must aggressively set up physical boundaries using G22 chuck and tailstock barrier check functions. Or, if tool transitions require waiting, programming a dwell cycle lets active forces dissipate before transitioning systems. Additionally, operators must routinely run dry-run graphics to visually validate all stroke limits before initiating live spindle cutting on the shop floor.

Related Command Network

  • G28 (Reference Position Return) - Essential for returning axes to the machine home before executing unit changeovers to prevent position-based coordinate shift alarms.
  • G70 / G71 (Inch/Metric Input) - Native geometric unit selection commands utilized on Siemens and optionally on Fanuc setups via parameter configurations.
  • G700 / G710 (Inch/Metric Technological Scaling) - Extended native commands in Siemens that convert coordinates, compensations, and technological feedrates concurrently.
  • G22 / G23 (Chuck/Tailstock Barrier Check) - Safeguards physical boundaries that depend on precise unit scaling to prevent indexable tooling collisions.
  • G94 / G95 (Asynchronous/Synchronous Feedrate Modes) - Establish active feedrate rates (inches per minute/revolution vs. millimeters per minute/revolution) which scale according to the active unit selection G-code.

Conclusion

Successful unit selection programming depends on a disciplined pre-checks protocol and parameter verification. Shop managers must document the state of tool offset and coordinate system conversion parameters across Fanuc, Siemens, and Mitsubishi controllers before permitting operators to load multi-unit programs. Standardizing on-machine verification—including returning all axes to reference positions via G28 and performing full graphic dry-run sweeps—eliminates coordinate scaling discrepancies before a cutting tool makes physical contact with stock material.

FAQ

Why does commanding G20 or G21 sometimes trigger a P34 or PS5362 alarm?

These alarms indicate that the controller's safety parameters are blocking an unguided unit change. In Fanuc systems, parameter 14000 bit 2 restricts G20/G21 switching exclusively to the reference position to prevent sudden kinematic offsets, triggering alarm PS5362 if violated. In Mitsubishi systems, parameter #1253 set25/bit1 locks out all mid-program unit conversions to maintain coordinate integrity, throwing a P34 error. To resolve this, operators must return the axes to reference using G28 before switching units, or request administrative parameter authorization to toggle the security lock.

Do program feedrate (F-word) values scale automatically when switching between G20 and G21?

Standard G20 and G21 codes scale coordinate dimensions only and do not recalculate active feedrates, meaning a feedrate programmed as F10.0 shifts from 10 inches per minute to 10 millimeters per minute (resulting in an extremely slow, tool-rubbing axis crawl). The major exception is Siemens native G700 and G710 commands, which scale technological feedrates alongside geometric values. To prevent slow axis crawls or excessive tool wear, programmers must explicitly declare a new, calculated F-word immediately following any unit change block in the program.

What is the risk of executing a G20/G21 switch when parameter offset conversions are disabled?

If parameters like Fanuc 5006 bit 0 (OIM), Siemens MD10260, or Mitsubishi #1226 are disabled, the controller will convert coordinate system movements but will leave the tool geometry and wear offsets in their old unit state. This leads to a severe scaling mismatch, where an offset meant to retract a tool by 0.05 inches is interpreted as a retraction of only 0.05 millimeters, causing the tool to cut too deep or crash. Machinists must verify these parameters are set to 1 in the control registers, and always run a dry-run toolpath trace on the graphics screen to verify offsets are scaled correctly prior to active spindle rotation.

Still not resolved?

Ask our AI assistant about this topic in natural language. Grounded in verified sources, no hallucinations.

Ask AI Assistant
Hakan Gündoğdu
Hakan Gündoğdu
  • CNC CARE Co-Founder (May 2025 - Present)
  • Mitsubishi Electric NC Sales & Service Section Manager (2008 - 2025)
  • Reis CNC Service Engineer (2003 - 2005)
  • Ören Kalıp CNC Mold Line Team Leader (1999 - 2002)

With over 25 years of experience working in all areas of the CNC machine industry, I continue my activities as a co-founder of CNC CARE, where we offer brand-independent consulting, engineering, and original spare parts services.

Related Articles

Other articles on this topic