A complete, updated G-code and M-code reference guide for CNC programming in 2025 and beyond. Understand every command used in CNC milling, turning, routing, and 5-axis machining. Includes examples, tables, and real-world applications.
📘 Introduction
Whether you’re just starting out in CNC or you’re a professional machinist, mastering G-code and M-code is non-negotiable. These command sets are the language CNC machines speak—essential for precision, automation, and innovation.
🧾 What is G-Code?
G-code (Geometric code) controls movements like positioning, cutting, and contouring. It tells the CNC machine *what to do* and *how to do it*. Every line matters in the final product’s accuracy.
🔠 Common G-Codes
Code | Function | Example |
---|---|---|
G00 | Rapid Positioning | G00 X50 Y50 |
G01 | Linear Interpolation (cut) | G01 X100 Y100 F150 |
G02 | Clockwise Arc | G02 X20 Y30 R10 |
G03 | Counterclockwise Arc | G03 X20 Y30 R10 |
G90 | Absolute Programming | G90 |
G91 | Incremental Programming | G91 |
G28 | Return to Machine Zero | G28 U0 W0 |
🧾 What is M-Code?
M-codes handle auxiliary machine functions such as spindle control, coolant, and program stops.
🔠 Common M-Codes
Code | Function | Example |
---|---|---|
M03 | Spindle ON (Clockwise) | M03 S1500 |
M04 | Spindle ON (Counterclockwise) | M04 S1000 |
M05 | Spindle OFF | M05 |
M06 | Tool Change | M06 T01 |
M08 | Coolant ON | M08 |
M09 | Coolant OFF | M09 |
M30 | End of Program (Reset) | M30 |
🔄 Modal vs Non-Modal Codes
Modal commands stay in effect until changed (e.g., G01). Non-modal commands only affect the current line (e.g., G04 dwell).
🎯 G-Code Groups Explained
- Group 01: Motion (G00, G01, G02, G03)
- Group 03: Plane Selection (G17, G18, G19)
- Group 05: Tool Compensation (G41, G42, G40)
- Group 09: Canned Cycles (G81, G83, G84)
📂 Real CNC Program Breakdown
O0100 (Sample Part) G21 G17 G90 G00 X0 Y0 G43 Z50 H01 M03 S1500 G01 Z-5.0 F100 G01 X50 Y0 M05 M30
🧠 Tips for Memorizing G & M Codes
- Group them by function (movement, tool, coolant)
- Use printable cheat sheets in your workshop
- Test on simulators like NC Viewer before live runs
🌐 Fanuc vs Siemens vs Haas Differences
Code | Fanuc | Siemens | Haas |
---|---|---|---|
Spindle ON | M03 | M03 | M03 |
Tool Change | M06 | M06 | Txx M06 |
End Program | M30 | M30 | M30 |
📊 Future of CNC Coding
- AI-generated G-code based on part geometry
- Voice-controlled CNC programming (natural language)
- Browser-based live code simulators
- G-code analyzers with automatic optimization
📥 Downloadable Resources
- PDF: Full G-code command sheet
- Printable M-code poster
- CSV file: G-code & M-code searchable list
✅ Conclusion
G-code and M-code are the universal languages of manufacturing. With the right knowledge and practice, these codes become a powerful tool in the hands of any CNC machinist or programmer. As automation and AI reshape the industry, your fluency in these command sets ensures you stay ahead in modern and future CNC workflows.
Leave a comment