Ultimate G-Code & M-Code Reference Guide for CNC Machining (2025 Edition)
Meta Description: The most complete and up-to-date G-code and M-code reference chart for CNC machines. Learn what each code does with real examples, usage tips, and machine-specific notes.
Every CNC machinist, operator, and programmer must master G-code and M-code. These alphanumeric commands are the fundamental instructions that control motion, tools, spindles, coolant, and more. Below you’ll find a full breakdown of the most widely used commands, along with examples and machine-specific variations (FANUC, Haas, Siemens).
📘 What are G-code and M-code?
- G-code (Geometric/Preparatory code): Instructs the machine on how to move (e.g., rapid, linear, circular motion).
- M-code (Machine code): Controls machine functions such as turning the spindle on/off, activating coolant, or changing tools.
🧭 Essential G-code List
| G-Code | Function | Description | Example |
|---|---|---|---|
| G00 | Rapid Positioning | Moves the tool quickly to a location without cutting | G00 X0 Y0 |
| G01 | Linear Interpolation | Moves the tool in a straight line with cutting | G01 X50 Y50 F150 |
| G02 / G03 | Arc Motion | G02 = Clockwise / G03 = Counterclockwise arcs | G03 X30 Y10 I-10 J0 |
| G17 / G18 / G19 | Plane Selection | G17 = XY / G18 = ZX / G19 = YZ | G17 |
| G20 / G21 | Units | G20 = Inches / G21 = Millimeters | G21 |
| G90 / G91 | Coordinate Mode | G90 = Absolute / G91 = Incremental | G90 |
| G40 / G41 / G42 | Tool Radius Compensation | G41 = Left / G42 = Right | G41 D01 |
| G81–G89 | Drilling Cycles | Various canned cycles for holes | G81 X0 Y0 Z-5 R1 F100 |
⚙️ Common M-code Reference
| M-Code | Function | Description | Example |
|---|---|---|---|
| M00 | Program Stop | Stops program until manual restart | M00 |
| M03 / M04 | Spindle Control | M03 = CW / M04 = CCW spindle rotation | M03 S1500 |
| M05 | Spindle Stop | Stops spindle rotation | M05 |
| M06 | Tool Change | Initiates a tool change | M06 T01 |
| M08 / M09 | Coolant Control | M08 = ON / M09 = OFF | M08 |
| M30 | End of Program | Resets machine and returns to start | M30 |
📄 Sample Program Using G/M Codes
%
O0100 (Simple Milling Program)
G21 G90 G17
G00 X0 Y0 Z5
M06 T01
M03 S1000
G00 X10 Y10
G01 Z-2 F100
G01 X50 Y10
G01 Y50
G01 X10
G01 Y10
G00 Z5
M05
M30
%
📈 CNC G-code Evolution (Future-Proofing)
With Industry 4.0 integration, modern CNC controls now include:
- Advanced macro programming (parametric G-code)
- Probing cycles using G31, G65
- AI-integrated CAM systems generating optimized paths
- IoT-connected G-code execution with real-time feedback
To remain competitive, machinists should familiarize themselves with adaptive control, in-process feedback commands, and custom post-processing techniques that evolve G-code into smart manufacturing tools.
📚 Bonus: G-Code Cheat Sheet (Printable)
- G00: Rapid move
- G01: Linear cut
- G02/G03: Arc (CW/CCW)
- G21: mm / G20: inch
- M03: Spindle CW
- M08: Coolant ON
- M30: End of Program
Download high-res printable versions (available soon on cnccode.com).
✅ Conclusion
Understanding G-code and M-code is essential to mastering CNC machining. This reference guide will continue to grow as new codes and smarter machine functions are introduced. Bookmark this page and visit cnccode.com regularly for the latest updates, printable charts, and interactive simulators.
Leave a comment