FEATURE
M-Codes List for CNC Machine Programming
What Are M-Codes?
M-codes are also called miscellaneous functions. Unlike G-codes, which prepare a CNC machine to use a particular cycle or mode, M-codes command machine functions such as starting the spindle, switching coolant on, changing a tool, or ending a program.
M-code support varies among CNC machine manufacturers and controllers. Always confirm a code and its behavior in the programming manual for the specific machine before using it.
Common CNC M-Codes
| Code | Function |
|---|---|
| M00 | Compulsory program stop |
| M01 | Optional program stop |
| M02 | End of program without rewind, usually with reset |
| M03 | Start spindle clockwise for right-hand tools |
| M04 | Start spindle counterclockwise for right-hand tools |
| M05 | Stop spindle |
| M06 | Automatic tool change |
| M07 | Turn coolant mist on, when available |
| M08 | Turn coolant on |
| M09 | Turn coolant off |
| M19 | Orient spindle |
| M30 | End program, reset, and rewind |
| M48 | Deactivate feed-rate override cancellation |
| M49 | Activate feed-rate override cancellation |
| M60 | Automatic pallet change |
| M78 | Clamp B axis; nonstandard |
| M79 | Unclamp B axis; nonstandard |
| M98 | Call a subprogram |
| M99 | End or return from a subprogram |
Programming Considerations
Many controllers permit only one M-code in a program block. Opposing commands such as M03 and M04 cannot be active together.
M98 can reduce repeated programming by calling a subprogram that performs the same operation multiple times. This can make a program shorter and easier to maintain and, depending on the application and controller, may help streamline the machining cycle.
The list above is not exhaustive. CNC machines often provide additional machine-specific miscellaneous functions. Consult the documentation for the individual milling or turning center to learn which codes are supported and how they behave.