Explore the ultimate G-Code and M-Code reference guide—covering every essential CNC command, real-world examples, syntax breakdowns, and tips for professional CNC programming and automation.
Complete G-Code and M-Code Reference for CNC Programmers and Machinists
Whether you are a beginner just learning CNC or a seasoned machinist, mastering G-Code and M-Code is essential. These command languages drive everything from basic movements to complex machining operations. This ultimate reference guide provides an in-depth, easy-to-navigate directory of standard and advanced G & M codes used in CNC milling, turning, and automation.
📘 Table of Contents
- 1. What Are G-Codes and M-Codes?
- 2. How CNC Machines Interpret Codes
- 3. Standard G-Code Commands List
- 4. Standard M-Code Commands List
- 5. Advanced G-Code Applications
- 6. G-Code Syntax and Programming Format
- 7. Differences Between Milling and Lathe G-Codes
- 8. Error Troubleshooting with G-Code
- 9. Online Simulators and Testing Tools
- 10. Printable G/M Code Cheat Sheet
1. What Are G-Codes and M-Codes?
G-Code (Geometric Code) controls movement and position (e.g., linear motion, arc paths). M-Code (Miscellaneous Code) controls machine-specific functions like spindle on/off, coolant, and tool changes.
2. How CNC Machines Interpret Codes
CNC controllers interpret the codes line-by-line in a program file (commonly .nc, .tap, or .gcode formats). Each line is typically one instruction, called a block.
3. Standard G-Code Commands List
G-Code | Description |
---|---|
G00 | Rapid positioning |
G01 | Linear interpolation (cutting motion) |
G02 | Circular interpolation clockwise |
G03 | Circular interpolation counterclockwise |
G17 | Select XY plane |
G20 | Set units to inches |
G21 | Set units to millimeters |
G28 | Return to machine home |
G40 | Cancel cutter compensation |
G90 | Absolute positioning |
G91 | Incremental positioning |
G94 | Feedrate per minute |
4. Standard M-Code Commands List
M-Code | Description |
---|---|
M00 | Program stop |
M01 | Optional stop |
M02 | End of program |
M03 | Spindle on clockwise |
M04 | Spindle on counterclockwise |
M05 | Spindle stop |
M06 | Tool change |
M08 | Coolant on |
M09 | Coolant off |
M30 | End of program + rewind |
5. Advanced G-Code Applications
- Parametric programming with variables (e.g., #100)
- Macros for loops and conditional logic
- Using subprograms with M98 and M99
- Tool radius compensation (G41, G42)
- High-speed roughing routines
6. G-Code Syntax and Programming Format
Each line follows a standard format: N10 G01 X1.0 Y1.0 F100
- N10 = Line number (optional)
- G01 = Motion command
- X1.0 Y1.0 = Position coordinates
- F100 = Feedrate
7. Differences Between Milling and Lathe G-Codes
While many codes are shared, lathe machines use additional turning codes (e.g., G96 for constant surface speed). Some machines use manufacturer-specific extensions or proprietary G/M codes.
8. Error Troubleshooting with G-Code
- ⚠️ Alarm 1: Limit switch triggered
- ⚠️ Alarm 20: Unsupported command
- ✅ Tip: Use a G-code viewer or simulator to verify code before machining
9. Online Simulators and Testing Tools
Try tools like:
- NCViewer – Free G-code visualizer
- CNCjs – Web-based G-code sender with preview
- CAMotics – 3D toolpath simulator
10. Printable G/M Code Cheat Sheet
We’ve created a compact cheat sheet of G-Code and M-Code commands for quick reference in the workshop. Download and print it to keep at your CNC station.
🔚 Conclusion
G-Code and M-Code remain the universal languages of CNC machines. Learning them unlocks full control over motion, tooling, safety, and automation. Whether you’re editing CAM output or writing code by hand, this guide will serve as your foundational reference for professional CNC programming.
Bookmark this page and return often for updates, expansions, and printable CNC cheat sheets. Only on cnccode.com.
Leave a comment