G-code Modal vs Non-Modal Commands: What They Are and Why They Matter
In CNC programming, understanding the difference between modal and non-modal commands is key to writing efficient and error-free code.
Let’s break down what these terms mean, how they affect your program, and why they are critical for CNC safety and reliability.
🧠 What is a Modal G-code?
A modal command stays active until it is changed by another command from the same group. Think of it as a “sticky” setting — once it’s on, it remains active across all future blocks.
📌 Example:
G1 X50 Y50 F200 ; Linear move with feedrate
X100 Y100 ; Still G1 and F200, even though not repeated
Here, G1 and F200 are modal — they stay in effect unless explicitly changed.
🔁 What is a Non-Modal G-code?
A non-modal command executes only on the line it appears. It does not persist to future blocks.
📌 Example:
G4 P1 ; Dwell for 1 second
G0 X0 Y0 ; G4 no longer in effect
In this case, G4 (dwell) is non-modal — it happens once, then ends.
📋 Modal Groups in G-code
Modal commands are organized into modal groups. Only one code from each group can be active at a time.
| Modal Group | Function | Examples |
|---|---|---|
| Group 1 | Motion | G0, G1, G2, G3 |
| Group 2 | Plane selection | G17, G18, G19 |
| Group 3 | Distance mode | G90, G91 |
| Group 5 | Feed rate mode | G94, G95 |
| Group 6 | Units | G20, G21 |
| Group 7 | Cutter comp | G40, G41, G42 |
| Group 8 | Tool length offset | G43, G49 |
| Group 9 | Canned cycles | G81–G89 |
| Group 10 | Return mode | G98, G99 |
| Group 12 | Coordinate system | G54–G59 |
🧠 Modal groups are mutually exclusive — only one G-code from each group can be active at once.
🧠 Why Modality Matters
Understanding modality is important because:
- It avoids redundant code (e.g., repeating G1 every line)
- Helps diagnose bugs where behavior seems to “stick”
- Ensures correct execution order
- Prevents unexpected machine moves
🛠️ Modal Example: Motion Mode
G1 X10 Y10 F150 ; Linear move
X20 ; Same feed and motion mode still apply
G0 X0 ; Switch to rapid
What happens here?
- First move: Linear feed at 150 mm/min
- Second move: Same mode, still G1
- Third move: Rapid move (G0 takes over motion mode)
🛠️ Non-Modal Example: Dwell and G53
G4 P2 ; Wait 2 seconds — non-modal
G1 X50 Y50 ; Continue with previous motion mode
G53 G0 Z0 ; Move in machine coords — non-modal
G1 X0 Y0 ; Back to modal feed move
G4andG53execute once, then return control to previous modes
⚠️ Common Mistakes With Modality
- ❌ Forgetting that a motion command persists (e.g., G1 causing slow feed when rapid expected)
- ❌ Assuming a non-modal command like G53 remains active (it doesn’t!)
- ❌ Using two codes from same modal group in the same block (may cause alarm)
✅ Best Practices
- ✅ Always specify important modal settings at the start of program
- ✅ Use comments to remind yourself of active modes
- ✅ Re-declare modal commands after tool changes or new operations
- ✅ Use non-modal codes carefully (e.g., G53, G4) and only when needed
🧩 Modal G-code Example Block
G90 G21 G17 ; Absolute mode, metric, XY plane
G54 ; Work coordinate system
G0 Z5 ; Rapid retract
G43 H1 ; Tool length offset
M8 ; Coolant on
Each line sets a modal state that persists until changed.
📌 Modal vs Non-Modal Quick Reference
| Code | Modal? | Group | Description |
|---|---|---|---|
| G0 | Yes | 1 | Rapid move |
| G1 | Yes | 1 | Linear interpolation |
| G2 | Yes | 1 | CW arc |
| G90 | Yes | 3 | Absolute positioning |
| G91 | Yes | 3 | Relative positioning |
| G20 | Yes | 6 | Inch mode |
| G21 | Yes | 6 | Metric mode |
| G4 | No | — | Dwell (pause) |
| G53 | No | — | Machine coordinate move |
| M3 | Yes | — | Spindle CW |
| M5 | Yes | — | Spindle stop |
🔚 Final Words
Modal and non-modal G-codes are like machine memory states. Understanding how they persist (or don’t) is crucial to:
- Avoid crashes
- Simplify your code
- Make edits confidently
- Debug unexpected machine behavior
Once you master modality, you gain true control over your CNC machine.
Leave a comment