G21 Metric (mm) Input G-Code Command: CNC Programming Guide
Master the G21 metric G-code command for Fanuc, Siemens, and Mitsubishi. Learn block syntax rules, critical parameters like #1041, and how to avoid turret crashes.
Introduction
Executing a metric G-code program on a CNC control default-configured for imperial units results in a catastrophic turret collision that shatters tooling, fractures the machine spindle, and destroys the workpiece. When the control preprocessor reads a position command like X60.0, it interprets the value as 60.0 inches instead of the intended 60.0 millimeters. This scaling error drives the lathe turret off-trajectory at rapid traverse velocity, plunging the tool carrier straight into the rotating chuck jaws, tailstock, or table-mounted clamps. The machine stops only after the hardware impact triggers a critical axis overtravel alarm code, leaving the shop floor with a scrap part and expensive machine damage. Operators prevent these physical crashes by programming the G21 metric command to set the proper measurement system before any motion occurs, or after toggling from the G20 inch input mode.
Technical Summary
| Feature | Technical Specification |
|---|---|
| Command Code | G21 (Fanuc System A/B, Siemens ISO Dialect, Mitsubishi), G71 (Fanuc System C), G710 (Siemens Native) |
| Modal Group | Group 06 (Modal coordinate system units) |
| Supported Brands | Fanuc, Siemens, Mitsubishi |
| Critical Parameters | Fanuc No. 3401 DPI / No. 5040 TCT, Siemens MD10240 SCALING_SYSTEM_IS_METRIC, Mitsubishi #1041 I_inch / #1003 iunit |
| Main Constraint | Applies strictly to linear axes; rotary axes continue to evaluate inputs in degrees. Must be programmed in its own independent block at the start of the program. |
Quick Read
- Place G21 in the very first block of the program before executing any axis moves, tool offsets, or workpiece coordinate system settings.
- Program the G21 command entirely alone in an independent block to prevent parser format syntax errors.
- Realize that toggling between G20 and G21 does not mathematically convert active values; it shifts the decimal point, scaling coordinate values ten times or more.
- Manually calculate and input wear and geometry compensations in the offset table when switching program units on Mitsubishi controls since screens remain bound to parameter #1041.
- Configure virtual electronic boundaries on the Chuck Barrier and Tailstock Barrier screens to prevent physical turret contact in case of unit mismatches.
- Cancel all active tool compensations before modifying tool offset shift parameters (such as Fanuc No. 5040 bit 3) to avoid triggering a PS0368 alarm.
Basic Concepts
The preparatory command G21 establishes a modal coordinate environment where the CNC interpreter parses all subsequent linear coordinates, circular interpolation parameters, thread leads, and offset shifts in millimeters. This metric input mode ensures that the controller scales programmed coordinates to match the physical metric resolution of the machine axes. During manual operation, activating G21 changes the handwheel index divisions to represent metric increments of 0.001 mm, 0.010 mm, and 0.100 mm. Operators must verify the active unit mode before rotating the handwheel to prevent manual indexing errors caused by mismatched scale resolutions.
Uncoordinated transitions between G20 and G21 during execution create severe physical hazards. When a control switches modes, it does not convert the physical dimension; instead, it shifts the decimal point. A coordinate value of X6.0 inches under G20 translates directly to X6.0 mm when G21 is active, rather than the correct mathematical equivalent of 152.4 mm. To protect the machine, operators must configure virtual electronic envelopes on the Chuck Barrier and Tailstock Barrier screens. These safety boundaries define entry-prohibited zones that halt the axes and trigger a stroke limit alarm before the turret strikes the workholding equipment.
Command Structure
The syntax for metric programming is standardized across ISO-compliant CNC systems, requiring the G21 command to occupy an independent program block at the start of execution. Placing G21 in the same block as coordinate motions or auxiliary functions violates scanner parsing rules and causes the preprocessor to halt execution. The command acts as a modal switch, meaning that once it is executed, all subsequent coordinates are parsed as millimeters until a G20 command selects imperial units.
While G21 changes how coordinates in the active G-code program are read, it does not automatically scale background system parameters. Tool geometry offsets, work coordinate shifts, and feedrate values may continue to follow the machine default basic measuring system. Programmers must write a new feedrate value immediately after calling G21 to ensure that axis travel speeds are computed in millimeters per minute or millimeters per revolution.
G21 ;| System Address / Parameter | Function and Value Range | Applicable CNC Brand |
|---|---|---|
| Parameter No. 3401 Bit 0 (DPI) | Controls decimal point programming. When set to 0, Z1000 evaluates to 1.0 mm in G21. | Fanuc |
| Parameter No. 5040 Bit 3 (TCT) | Governs tool offset and tool length compensation shift types (0 or 1). | Fanuc |
| MD10240 (SCALING_SYSTEM_IS_METRIC) | Defines default basic measuring system of the machine. Set to 1 for metric, 0 for inch. | Siemens |
| MD18800 (MM_EXTERN_LANGUAGE) | Enables external language mode when set to 1, allowing G21/G20 processing. | Siemens |
| Parameter #1041 I_inch | Determines the default HMI display counters, offset screens, and parameters (0 for inch, 1 for metric). | Mitsubishi |
| Parameter #1003 iunit | Sets input setting resolution. Values: B (0.001 mm), C (0.0001 mm), D (0.00001 mm), E (0.000001 mm). | Mitsubishi |
Brand Applications
Fanuc
Fanuc controls use G21 to select metric command units, which shifts the interpretation of coordinates like X, Z, C, and Y under Lathe G-code System A. The system behavior is governed by Parameter No. 3401 Bit 0 DPI and Parameter No. 5040 Bit 3 TCT.
The G21 command must be programmed in an independent block at the very beginning of the program: G21 ;.
| Category | Identifier / Setting | Description |
|---|---|---|
| Parameters | Parameter No. 3401 Bit 0 (DPI) | Controls decimal point programming. When set to 0, Z1000 evaluates as 1.0 mm in G21. |
| Parameters | Parameter No. 5040 Bit 3 (TCT) | Governs tool offset and tool length compensation shifts. Modifying it during active offsets triggers Alarm PS0368. |
| Parameters | Parameter No. 1004 Bit 7 (IPR) | Determines if least input increment is 10 times greater than least command increment. |
| Alarms | Alarm PS0368 | Occurs when Parameter No. 5040 Bit 3 is changed while tool offsets are actively applied. |
| Alarms | Alarm PS0011 | "FEED ZERO (COMMAND)" - Cutting feedrate exceeds parameter limit or is zero. |
| Alarms | Alarm PS0201 | "FEEDRATE NOT FOUND IN RIGID TAP" - Programmed thread feedrate exceeds upper limit in rigid tapping. |
| Versions | G-code System C | Uses G71 for metric input and G70 for inch input instead of G21/G20. |
| Versions | Parameter No. 0001 Bit 1 (FCV) | Enables legacy Series 15 program format when set to 1, disabling canned cycle roughing allowances. |
Uncoordinated coordinate unit shifts while running in G20 mode will scale coordinates tenfold, forcing the tool turret off-trajectory and creating a severe risk of a hard collision with the spindle chuck. Unlike G17 for the XY plane or G18 for the ZX plane, which govern circular interpolation planes, G21 dictates the fundamental length values of all linear motions.
Siemens
Siemens controls parse G21 when executing in ISO Dialect Mode (G291) to define coordinate systems in millimeters. Default scaling and interpreter resets are managed by MD10240 and MD20154.
To use G21, the compiler must switch to ISO Dialect Mode (G291) and initialize the code on its own line: G291 ; G21 ;.
| Category | Identifier / Setting | Description |
|---|---|---|
| Parameters | MD10240 (SCALING_SYSTEM_IS_METRIC) | Defines basic default measuring system of the control. Registers not scaled by G21 follow this setting. |
| Parameters | MD18800 (MM_EXTERN_LANGUAGE) | General machine data set to 1 to enable external ISO dialect interpretation. |
| Parameters | MD20154 (EXTERN_GCODE_RESET_VALUES) | Channel-specific data setting default active Group 6 code (G20/G21) upon power-up/reset. |
| Parameters | MD20734 Bit 3 | Controls whether scanner errors generate alarms (0) or silent-forward to Siemens mode (1). |
| Alarms | Alarm 61800 | "External CNC system missing" - Triggered if G21 is run while MD18800 is disabled. |
| Alarms | Alarm 14800 | "programmed path velocity is less than or equal to zero" - Omitted or zero feedrate during G21. |
| Alarms | Alarm 12080 | "unknown G-code" - Unrecognized external G-code processed with MD20734 Bit 3 set to 0. |
| Versions | SINUMERIK 802D sl | MD20154 reset values and MD22515 PLC configurations are read-only and locked. |
| Versions | SINUMERIK 810D | Certain advanced vocabulary words or cycles are invalid on legacy systems. |
Failing to program a new feedrate F command after toggling G21 causes incorrect axis velocities and triggers path velocity Alarm 14800.
Mitsubishi
Mitsubishi controls implement G21 to interpret coordinates in millimeters for all linear axes. Setting and display units at power-on are governed by parameter #1041 and parameter #1003.
The command must be placed completely alone in its own block: G21 ;.
| Category | Identifier / Setting | Description |
|---|---|---|
| Parameters | Parameter #1041 I_inch | Determines the default HMI display counters, offset screens, and parameters (0 for inch, 1 for metric). |
| Parameters | Parameter #1003 iunit | Input setting unit configuring input resolution: B (0.001 mm), C (0.0001 mm), D (0.00001 mm), E (0.000001 mm). |
| Parameters | Parameter #1015 cunit | Program command unit axis resolution. Accepts 0 (follows #1003) or scaling factors up to 10000. |
| Parameters | Parameter #1210 RstGmd Bit 5 | Determines if Group 06 modal G-codes (G20/G21) are reset or retained after a system reset. |
| Alarms | Program Error P33 | "Illegal G-code command format" - Triggered if G21 is in the same block as other commands. |
| Alarms | Program Error P162 | Triggered if unit systems are toggled while 3D tool radius compensation (G41.2/G42.2) is active. |
| Alarms | Program Error P452 | Triggered if axis movement crosses into entry-prohibited Chuck or Tailstock Barriers. |
| Versions | Software Version C3 | Introduced G188/G189 format switches to dynamically swap Lathe and Machining Center parsers. |
| Versions | Modern M8 Series | Does not support parameter input by program N-numbers (G10 L50...G11), which is restricted to legacy models. |
Since Mitsubishi offset registers are locked to parameter #1041 I_inch, G21 does not scale screens or tool geometry tables; failure to manually calculate offsets will cause incorrect axis positioning.
Brand Comparison
| Feature | Fanuc | Siemens | Mitsubishi |
|---|---|---|---|
| Command Syntax | G21 (G71 in System C) | G21 (ISO Dialect Mode G291) | G21 |
| Native Mode Metric Equivalent | None (or G71 in System C) | G71 / G710 (automatic scaling of coordinate and feed values) | None |
| Scaling Behavior (G20 to G21 shift) | Decimal shift (merely shifts decimal point of coordinates, e.g. X60.0 mm to X6.0 inches under G20) | Decimal shift under G20/G21; native G710 automatically scales positions and feedrates | Decimal shift; display screens and offset tables are locked by parameter #1041 I_inch |
| Lathe Coordinate Syntax | System A uses coordinate addresses X/Z/C/Y for absolute and U/W/H/V for incremental | Supports G291 ISO dialect System A coordinates | Lathe L-system uses absolute X/Z/Y and incremental U/W/V |
| Locked Parameters & Constraints | None | Reset configuration MD20154 and PLC transfer MD22515 are read-only on SINUMERIK 802D sl | PLC window read/write is permanently fixed to metric units; offsets are locked by parameter #1041 I_inch |
| Dynamic Program Parser Switch | Parameter No. 0001 Bit 1 (FCV) enables legacy Series 15 format | G290/G291 switches between Siemens native and ISO dialect modes | G188/G189 dynamically switches between Lathe L-system and Machining Center M-system G-code tables |
Technical Analysis
Analytical comparison of unit systems reveals distinct preprocessor logic across these control platforms. Fanuc utilizes G-code Systems A, B, and C to switch unit systems, forcing lathe programmers using System C to command G71 instead of the standard G21. Additionally, Fanuc lathe configurations under System A reject standard modal G90/G91 states. In System A, coordinate address letters dictate coordinate type, with absolute paths specified by X or Z and incremental paths by U or W. Programmers must remember that commanding G90 on a System A Fanuc lathe starts a longitudinal turning canned cycle rather than setting absolute mode.
Siemens approaches metric input through dual-interpreter structures. Instead of relying on background calculations within a single parser, Siemens isolates legacy G21 commands within ISO Dialect Mode (G291). Programmers can switch to native Siemens Mode (G290) to execute native metric scaling commands like G710. Unlike standard ISO G21, which only alters coordinate parsing, native Siemens G710 scales both geometric coordinates and feedrates. Siemens also restricts reset settings on compact models like the 802D sl series, where channel reset parameters are locked, preventing direct on-screen modifications.
Mitsubishi separates program command units from HMI input settings. Modifying G21 only affects G-code program blocks, leaving screen displays and tool offset registers bound to parameter #1041. Operators must manually recalculate tool geometry when running programs in units that differ from the HMI configuration. Mitsubishi also implements a permanently locked metric PLC window interface. Regardless of G20 or G21 commands, PLC data transfers are processed in metric, requiring background logic to maintain millimeter values. For dynamic operations, Mitsubishi uses the G188 and G189 program format switches to swap modal G-code structures between lathe and machining center modes mid-run.
Program Examples
Fanuc Code Example
G21 ;
G00 X12.0 Z72.0 ;
G01 X120.0 W14.0 F0.15 ;dry run
During a dry run of this Fanuc program, the preprocessor evaluates coordinates in millimeters. In the first block, G21 initializes the metric mode. The turret rapid-positions (G00) to absolute diameter X12.0 mm and absolute longitudinal coordinate Z72.0 mm. In the final block, the tool advances at a cutting feedrate of 0.15 mm/rev (G95) to an absolute diameter of X120.0 mm while moving incrementally 14.0 mm in the positive Z-axis direction.
Siemens Code Example
G291 ;
G21 ;
G00 X80. Z80.8 ;
G290 ;
G710 X20.0 Y30.0 F500.0 ;dry run
During a dry run of this Siemens program, G291 switches the compiler to ISO Dialect Mode. The G21 command sets the metric system. The axes move to absolute coordinates X80.0 mm and Z80.8 mm under rapid traverse. The G290 command then toggles the interpreter back to Siemens native mode. Under native mode, the G710 command scales coordinates to X20.0 mm and Y30.0 mm, while automatically scaling the feedrate to 500.0 mm/min.
Mitsubishi Code Example
G21 ;
G00 X100.0 Y100.0 Z50.0 ;
G01 G41 X120.0 Z-80.0 F150.0 ;dry run
During a dry run of this Mitsubishi program, the G21 command establishes metric command units. The machine axes rapid-position to absolute coordinates X100.0 mm, Y100.0 mm, and Z50.0 mm. The axes then execute a linear interpolation (G01) feed movement to X120.0 mm and Z-80.0 mm at 150.0 mm/min feedrate (G94) with left-side tool radius compensation (G41) active.
Error Analysis
| Brand | Alarm Code | Trigger Condition | Operator Symptom | Root Cause / Fix |
|---|---|---|---|---|
| Fanuc | Alarm PS0368 | Modifying Parameter No. 5040 Bit 3 (TCT) while tool offset compensations are actively applied in the registers. | The CNC control halts automatic operation and displays Alarm PS0368 on the HMI. | Tool length or offset compensation is active. Cancel all active offsets in the program before changing the parameter. |
| Fanuc | Alarm PS0011 | Programmed cutting feedrate F command is zero or exceeds maximum limit in parameters. | Machine axes stop moving during feed blocks and display "FEED ZERO (COMMAND)" on the screen. | The F value is omitted, set to zero, or configured too high. Verify and input a valid feedrate parameter. |
| Fanuc | Alarm PS0201 | Programmed thread feedrate exceeds the upper limit or velocity for rigid tapping. | Spindle rotation and feed axis synchronization fail; tapping cycle halts with Alarm PS0201. | Feedrate in rigid tapping exceeds the maximum allowable cutting feedrate limit. Adjust the feedrate value. |
| Siemens | Alarm 61800 | Running a G21 program in ISO dialect without external language parameter MD18800 or option bit 19800 enabled. | The NC program halts instantly upon reaching the ISO mode transition block. | External language option is disabled. Set machine data MD18800 to 1 and verify option configuration. |
| Siemens | Alarm 14800 | Cutting travel feedrate F evaluates to zero or is omitted under G21. | Axes stall during interpolating paths; screen displays Alarm 14800 for zero velocity. | The control does not scale feedrate automatically when switching units. Program an F value immediately after the unit switch. |
| Siemens | Alarm 12080 | Unrecognized G-code command encountered under ISO Dialect Mode while MD20734 Bit 3 is set to 0. | The parser stops scanning and displays "unknown G-code/WAIT/G500" error. | Invalid syntax or command. Check G-code program syntax or set MD20734 Bit 3 to 1 to forward block to Siemens mode. |
| Mitsubishi | Program Error P33 | Programming G21 or G20 in the same block as coordinate movements, feedrates, or other preparatory commands. | CNC screen displays "Illegal G-code command format" and blocks program startup. | Format violation. Write the G21/G20 command in its own independent block at the beginning of the program. |
| Mitsubishi | Program Error P162 | Toggling inch/metric units while 3D tool radius compensation (G41.2/G42.2) is active. | The program execution halts mid-block with a Program Error P162 message. | Deactivate 3D tool radius compensation using G40 before switching unit codes. |
| Mitsubishi | Program Error P452 | Travel command end point or path crosses into entry-prohibited Chuck/Tailstock Barriers or stored stroke limits. | The control halts axis movement before physical contact occurs and displays Program Error P452. | Trajectory path goes inside virtual safety boundaries. Adjust the safety envelope parameters or modify coordinate points. |
Application Note
Crashing the lathe turret into rotating workpiece chuck jaws, the tailstock body, or table-mounted clamps is the direct result of executing a program with uncoordinated unit coordinates. Because standard G21 selections merely shift the decimal point without mathematically converting offset registers, any program mismatch scales coordinates tenfold. When the preprocessor executes rapid traverse commands (G00) under mismatched units, it drives the tool post off-trajectory into workholding fixtures, causing a hard collision that shatters tooling and fractures the machine spindle. To prevent this mechanical damage, operators must configure virtual electronic envelopes on the Chuck Barrier and Tailstock Barrier screens. This establishes an entry-prohibited safety envelope that automatically halts axis travel and triggers a stored stroke limit alarm before physical tool contact occurs.
Related Command Network
- G20: Selects imperial/inch input mode for linear coordinates within Group 06, which acts as the direct toggle cancel for G21.
- G71: Selects metric length dimensioning in native Siemens Mode (G290) or Fanuc Lathe G-code System C.
- G710: Selects metric scaling in native Siemens Mode (G290) for both geometric coordinates and technological feedrate values.
- G188: Enables the dynamic program format switch on Mitsubishi systems to swap modal G-code lists mid-run.
- G95: Selects feed-per-revolution mode, which evaluates cutting feedrates in metric increments of 0.01 mm/rev under G21.
Conclusion
Safeguarding CNC machinery against catastrophic axis crashes requires G21 to be initialized in an independent block at the very beginning of the program. Combining this preparatory command with a physical verification of the HMI offset units and active Chuck Barrier envelopes ensures the turret remains on its programmed trajectory.
Frequently Asked Questions
Why does the CNC control display a P33 or PS0368 alarm when programming G21?
A P33 alarm indicates a block formatting violation where G21 was combined with axis movements or feedrate commands, while a PS0368 alarm on Fanuc indicates that a tool offset shift parameter was modified while offset compensations were active. To fix these issues, isolate the G21 command on its own line at the beginning of the program, and cancel all active offsets before modifying parameter No. 5040.
Does G21 automatically scale tool offsets and feedrates on all control brands?
Standard G21 only alters coordinate parsing in the active G-code program and does not scale active tool offset tables or feedrates, which remain governed by default machine parameters. To scale both coordinates and feed values dynamically, use G710 in Siemens native mode or manually adjust tool wear geometries and program new feed rates immediately after toggling units.
How do Chuck and Tailstock Barriers prevent collisions during unit switching errors?
These virtual barriers define entry-prohibited boundaries for the tool reference point, allowing the control system to halt axis travel before physical contact occurs. Operators must input accurate fixture dimensions on the barrier settings screens during setup to ensure the control triggers a stroke limit alarm before the turret strikes the chuck or clamps.
Still not resolved?
Ask our AI assistant about this topic in natural language. Grounded in verified sources, no hallucinations.

- CNC CARE Co-Founder (May 2025 - Present)
- Mitsubishi Electric NC Sales & Service Section Manager (2008 - 2025)
- Reis CNC Service Engineer (2003 - 2008)
- Ö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
G27 Reference Position Return Check: CNC Guide for Multi-Brand Systems
Master the CNC G27 reference position return check on Fanuc, Siemens, and Mitsubishi controls. Learn parameters like MD 34100 and fix Alarm 61816.
Siemens SINUMERIK G26 Upper Working Area & Spindle Speed Limit
Master the Siemens SINUMERIK G26 command for upper working area and spindle speed limits. Learn syntax, parameters like SD 43420, and alarms to avoid crashes.
G26 Spindle Speed Fluctuation Detection ON: CNC Programming Guide
Learn how to configure G26 on Fanuc, Siemens, and Mitsubishi CNC controls to prevent spindle speed fluctuations, set travel limits, and avoid tool crashes.
G25 Lower Working Area and Spindle Speed Limit: Siemens CNC
Master G25 lower working area and spindle speed limits on Siemens SINUMERIK controls. Avoid chuck collisions and configure safety parameter SD 43430.