Top 100 Hidden G-Codes and M-Codes for CNC Machines
Discover the most secret, undocumented, and underused G/M codes across major CNC brands.
⚠️ Disclaimer: These codes are machine-specific and may not be supported on all models or versions. Always test on a simulator or non-critical job first!
🔍 Why Hidden G/M Codes Matter
Most CNC operators are familiar with standard G-codes (like G01 for linear feed or G28 for return to zero). However, each CNC controller brand includes hidden, OEM-only, or lesser-known codes that can unlock powerful features, diagnostics, or automation.
🧠 Hidden Codes by Brand
🔧 Fanuc Hidden G/M Codes
| Code | Description |
|---|---|
| G10 | Programmatic offset setting (dynamic work offset setting) |
| G22 | Soft limit ON |
| G23 | Soft limit OFF |
| G25 | Spindle speed detection ON |
| G26 | Spindle speed detection OFF |
| G31 | Skip function (useful for probing) |
| G65 | Custom macro call |
| M19 | Spindle orientation |
| M29 | Rigid tapping enable |
| M78 | Synchronous tapping ON |
| M88 | Coolant through spindle ON |
| M89 | Coolant through spindle OFF |
| M198 | Subprogram call from memory card |
🛠️ Haas Hidden G/M Codes
| Code | Description |
|---|---|
| G103 | Look-ahead buffer control |
| G131 | Cancel polar coordinates |
| G150 | Pocket milling cycle |
| G187 | Smoothness control |
| M21 | Tailstock advance |
| M22 | Tailstock retract |
| M50 | Macro variable print to screen |
| M97 | Local subroutine call |
| M99 | Subprogram end and return |
⚙️ Siemens Hidden G/M Codes
| Code | Description |
|---|---|
| G110-G129 | Additional work offsets |
| G601 | Engraving cycle |
| G799 | Custom probing cycle |
| M17 | Unlock rotary axis brake |
| M18 | Lock rotary axis brake |
| M166 | High pressure coolant ON |
| M167 | High pressure coolant OFF |
| M203 | Synchronous spindle mode |
| M204 | Asynchronous spindle mode |
🧾 Heidenhain Hidden Codes
| Code | Description |
|---|---|
| CYCL DEF 247 | Probing pattern (Z-surface + angle) |
| Q parameter codes | Conditional logic within programs |
| M120 | Activate pallet changer |
| M91 | Tool length measure cycle |
| M92 | Tool radius measure cycle |
| M128 | 3D cutter compensation |
| M140 | Reset safety zones |
| M226 | Reset probing error flags |
🏭 Mazak (Mazatrol) Hidden Codes
| Code | Description |
|---|---|
| G220 | Advanced tool life management |
| G131 | Coordinate rotation cancel |
| G144 | User-defined coordinate |
| M115 | Auto door open |
| M116 | Auto door close |
| M300 | Chip conveyor forward |
| M301 | Chip conveyor reverse |
| M800 | Workpiece measuring cycle |
| M810 | Tool setting cycle |
🔐 Top 20 Universal Secret Codes
These are found across multiple brands (check your controller compatibility).
| Code | Description |
|---|---|
| G10 | Set offsets from within a program |
| G53 | Move in machine coordinate system |
| G65 | Macro subroutine with arguments |
| G84.2 | Peck tapping cycle |
| M00 | Program stop |
| M01 | Optional stop |
| M99 | Subprogram loop or return |
| M78/M79 | Synchronous spindle pairing |
| M88/M89 | Through-spindle coolant |
| G31 | Probe skip |
| G66 / G67 | Modal macro call ON/OFF |
| G68 / G69 | Coordinate rotation ON/OFF |
| G187 | Contour control (Haas only) |
| G701–G709 | Custom cycles |
| M120–M130 | Auto-door, pallet, and probe logic |
| M300+ | Chip conveyors, high-pressure pump logic |
| G131 | Cancel polar or rotary |
| G110–G129 | Extended work offsets |
| M198 | Memory card subprogram call |
| G800+ | OEM-protected cycles |
🛑 Safety Tips
- Always simulate before running unknown codes.
- Hidden codes can override safety limits, offsets, or tool data.
- Backup your parameters and system settings regularly.
- Consult your machine’s maintenance mode or ladder logic view (Fanuc/Siemens) to uncover OEM options.
✅ Pro Tip: How to Discover Hidden Codes on Your Machine
- Check the Ladder Logic (Fanuc: press
SYSTEM > PMC). - Search OEM manuals or hidden PDFs from the controller manufacturer.
- Try macro variable logging with
#3003=3and#3004=3for timing diagnostics. - Use a USB sniffer to intercept M198 / G-code commands run from external memory.
📦 Bonus: Hidden Diagnostic Modes
| Controller | Access Key Combo | Purpose |
|---|---|---|
| Fanuc | MENU > SYSTEM > OFFSET > PWE = 1 | Parameter write enable |
| Haas | DEBUG at power-up | Service mode |
| Siemens | NC Start + Reset + Service | Machine test routines |
| Heidenhain | MOD + CE | PLC view |
| Mazak | Password protected | Ladder + Macro View |
📚 Resources for Further Exploration
- Fanuc Macro B Programming Manual (B-66230)
- Haas Operator Manual
- Siemens Sinumerik 840D Advanced Manual
- Heidenhain iTNC530 Cycles Manual
- Mazatrol SmoothX Programming Guide
🧠 Conclusion
Unlocking hidden G and M codes can transform how you program and operate CNC machines. From debugging and diagnostics to automation and optimization — these are the “cheat codes” of advanced CNC manufacturing.
Bookmark this page and experiment wisely. Precision awaits those who dare to go deeper.
Leave a comment