What Is M-Code in CNC? Full Meaning, Applications, and M-Code List

Jacky Gao
2025-10-11



What Is M-Code in CNC ? Full Meaning, Applications, and M-Code List


cnc-machine-controls-male-hand-2024-09-16-19-39-03-utc (1).jpg



In CNC machining, M-Code plays a vital role in controlling the machine’s auxiliary functions—everything that is not directly related to cutting paths or tool movements. While G-Codes define “how the machine moves”, M-Codes define “what the machine does”. For machinists, understanding M-Codes is essential for writing efficient and safe CNC programs. In this guide, we’ll explain the meaning of M-Code, its applications, what it can do in CNC, and include a complete Fanuc M-Code list, as well as common troubleshooting tips.


1. What Is M-Code?


M-Code stands for “Machine Code.” It is a set of instructions in CNC programming that controls auxiliary functions such as spindle on/off, coolant control, tool changes, and program stops. While G-Codes (Geometry Codes) manage tool motion, M-Codes handle machine-level commands that make those movements possible. Together, they form the foundation of CNC automation.

Examples include:


M03 – Spindle on (clockwise rotation)
M05 – Spindle stop
M08 – Coolant on
M09 – Coolant off
M30 – End of program and rewind


2. The Meaning of M-Code


Every M-Code carries a specific meaning that triggers an action in the CNC controller. Unlike G-Codes, which often have universal meanings across machines, M-Codes can vary slightly between machine brands (Fanuc, Haas, Siemens, etc.).


3. Applications of M-Code in CNC Machining




Function Type
Example M-Code
Description
Spindle Control
M03 / M04 / M05
Turn spindle on (CW/CCW) or off
Coolant Control
M07 / M08 / M09
Activate mist, flood, or turn off coolant
Tool Control
M06
Automatic tool change
Program Control
M00 / M01 / M30
Stop, optional stop, end of program
Chuck / Tailstock
M10 / M11 / M21 / M22
Open/close chuck, extend/retract tailstock
Safety / Door
M40 / M41
Gear range, safety locks, etc.




4. What Can M-Code Do?


M-Codes are the “hands and switches” of a CNC machine. They start and stop the spindle, control coolant and air blast, execute tool changes, manage machine doors and clamps, and end or pause the machining program.


5. M-Code List for Fanuc Control – Full Reference




M-Code
Function
M00
Program Stop
M01
Optional Stop
M02
End of Program
M03
Spindle On (CW)
M04
Spindle On (CCW)
M05
Spindle Stop
M06
Tool Change
M08
Coolant On
M09
Coolant Off
M10 / M11
Chuck Clamp / Unclamp
M19
Spindle Orientation
M30
End of Program and Rewind
M41 / M42
Gear Range (Low / High)
M60
Pallet Change (if available)




6. G-Code vs M-Code in CNC Programming


The difference between G-Code and M-Code is fundamental to CNC programming:



Aspect
G-Code
M-Code
Function
Controls motion (geometry)
Controls machine operations
Example
G01 = Linear cutting
M03 = Spindle on
Duration
Modal (remains active)
Non-modal (one-time action)
Focus
Path and feed control
Auxiliary functions


7. Common CNC M-Code Errors and Fixes




Problem
Possible Cause
Fix
Alarm: Invalid M-Code
Code not recognized by controller
Check if the M-Code is supported on your machine
Tool Change Error (M06)
Wrong tool number or offset
Verify tool offset table and magazine position
Coolant Not Activating (M08)
Coolant tank empty or disabled
Check coolant system and parameters
Program Not Ending Properly (M30)
Missing M02/M30 command
Always end with M30 or M02 to reset machine



Conclusion

Understanding M-Codes in CNC machining is crucial for writing safe, efficient, and automated programs. M-Codes enable the control of all auxiliary machine functions while working with G-Codes to complete machining operations.



Next:This is the last one
Prev:This is the first article