Master CNC programming with this complete 2025 reference for G-code and M-code commands. Includes standard, advanced, and machine-specific instructions with real-world examples.
The Complete G-Code & M-Code Reference Guide for CNC Machining (2025 Edition)
Whether you’re programming a CNC mill, lathe, or router, mastering G-code and M-code is essential for precision machining and automation. These command codes are the language that drives modern CNC machines. This 2025 edition reference guide explains every standard and commonly used G-code and M-code in clear detail, providing real examples, variations across control systems (like Fanuc, Siemens, Mach3, and GRBL), and practical tips for professional and hobbyist CNC programmers alike.
Table of Contents
- What is G-Code?
- What is M-Code?
- Standard G-Code Commands (ISO 6983)
- Standard M-Code Commands
- Fanuc vs. Siemens vs. Mach3 Variations
- Lathe-Specific G&M Codes
- Common CNC Programming Mistakes to Avoid
- G-Code Simulation & Debugging Tools
- G-Code Cheat Sheet PDF (Downloadable)
1. What is G-Code?
G-code, short for “Geometric code,” is the language that tells a CNC machine where and how to move its tools. It consists of commands that define axis motion (X, Y, Z), feed rates, tool paths, interpolation modes, and more.
Example:
G1 X10 Y20 F500
This tells the machine to move in a straight line to X10, Y20 at 500 mm/min feed rate.
2. What is M-Code?
M-code (Miscellaneous code) controls machine functions like coolant, spindle power, tool changes, and program stops. M-codes do not control motion directly but support operations required during machining.
Example:
M03 S1500
This turns the spindle ON clockwise at 1500 RPM.
3. Common G-Code Commands
| G-Code | Description | Example |
|---|---|---|
| G00 | Rapid positioning | G00 X50 Y25 |
| G01 | Linear interpolation | G01 Z-5 F300 |
| G02 | Circular interpolation CW | G02 X20 Y10 R5 |
| G03 | Circular interpolation CCW | G03 X20 Y10 I5 J0 |
| G17 | XY plane selection | G17 |
| G18 | XZ plane selection | G18 |
| G19 | YZ plane selection | G19 |
| G20 | Inches mode | G20 |
| G21 | Millimeters mode | G21 |
| G28 | Return to home | G28 X0 Y0 |
| G40 | Cancel cutter radius compensation | G40 |
| G90 | Absolute positioning | G90 |
| G91 | Incremental positioning | G91 |
| G94 | Feedrate per minute | G94 |
| G95 | Feedrate per revolution | G95 |
4. Common M-Code Commands
| M-Code | Description | Example |
|---|---|---|
| M00 | Program stop (operator interaction) | M00 |
| M01 | Optional stop | M01 |
| M02 | Program end | M02 |
| M03 | Spindle on clockwise | M03 S1200 |
| M04 | Spindle on counter-clockwise | M04 S800 |
| M05 | Spindle stop | M05 |
| M06 | Tool change | M06 T2 |
| M08 | Coolant ON | M08 |
| M09 | Coolant OFF | M09 |
| M30 | Program end and reset | M30 |
5. Fanuc vs. Siemens vs. Mach3/GRBL Variations
- Fanuc: Traditional codes, industry standard (G71-G73 cycles on lathes).
- Siemens: Uses ‘ShopMill’ or ‘Sinumerik’ conversational programming in parallel.
- Mach3/GRBL: Lightweight controllers, some codes like G76 may not be supported.
6. Lathe-Specific G & M Codes
| Code | Description |
|---|---|
| G71 | Rough turning cycle |
| G72 | Finishing cycle |
| G76 | Thread cutting cycle |
| M29 | Spindle synchronization for threading |
7. CNC Programming Mistakes to Avoid
- Forgetting G90 vs. G91 mode switch (absolute vs incremental)
- Incorrect tool offsets (G43, H values)
- Failing to use safe retracts before tool changes
- Leaving out M05 (spindle stop) before end of program
- Improper feedrate (F) resulting in tool breakage
8. G-Code Simulation Tools (Free & Paid)
- CNC Simulator Pro – Visualize G-code in 3D
- CAMotics – Open-source simulation engine
- NC Viewer – Lightweight online G-code viewer
- Fusion 360 Simulation – CAM-integrated preview
9. Downloadable G-Code Cheat Sheet (2025)
For a printable PDF version of the most important G & M codes, including axis reference diagrams and example subprograms, visit our resource page or contact us via CNCCode.com.
Conclusion
Mastering G-code and M-code is crucial for anyone working with CNC machines. Whether you’re writing manual code or reviewing CAM-generated toolpaths, understanding what each command does gives you better control, safety, and results. This reference guide is designed to be your ongoing CNC companion—bookmark it, print it, and share it.
The more fluent you become in CNC machine language, the more precise, efficient, and creative your machining projects will be.
Leave a comment