M codes play a critical in any CNC program. Using the wrong one or forgetting to use one at the right point in your program can mean the difference between a good part and a chunk of scrap.
We’ve laid out what each M code does, but remember that some CNC makers switch things around a little bit. You can bet that the most common codes such as the ones for starting and stopping your spindle, coolant and program will be the same but some of the others might vary.
M00 - Program Stop
When the machine gets to this code it will stop everything, including the spindle and coolant until the operator tells the machine to continue on.
M01 - Optional Stop
The machine will check the control panel and if the optional stop switch is on, the machine will stop just like with M00.
Programs often have optional stops placed at the break of sections in the program such as the start of a hole drilling sequence.
M02 - End of Program, No Rewind
A leftover from the NC days. Ends the program without rewinding to the start again.
In many machines now, M02 is no different than M30. How it gets treated depends on the specific CNC control model.
M03 - Spindle On, Clockwise
Turns the spindle on in the clockwise direction. This is the spindle direction used by most cutting tools.
M04 - Spindle On, Counterclockwise
Turns the spindle on in the counterclockwise direction.
M05 - Spindle Stop
Stops the machine spindle.
M06 - Tool Change
M07 - Coolant On, Mist
Turns on a coolant mist. Some machines treat it as coolant source 1 on.
M08 - Coolant On, Flood
Turns the coolant on to soak the workpiece. Some machines treat it as coolant source 2 on.
M09 - Coolant Off
Turns off all coolant sources.
M19 - Orient Spindle
Gets the tool ready for tool change. Aligns the keyways.
The M06 code will do this as well but calling it ahead of time can make the tool change process faster.
M30 - End of Program, Rewind
Stops everything including the spindle, movement, coolant and will go back to the beginning of the program.
M98 - Sub Program Call
Starts a subprogram.
M99 - End of Sub Program
Ends a subprogram.
Frequently Asked Questions
What are M codes used for in a CNC program?
M codes are used for turning miscellaneous functions on and off such as the spindle and coolant.
What is the difference between G and M codes?
M codes turn things on and off while G codes switch modes in the machine such as working in inches or mm.
G codes also prepare the machine for functions such as canned cycles for drilling or boring holes.
What other types of CNC codes are used?
There are many other CNC codes that get used such as:
- Location based codes such as A, B, C, I, J, K, X, Y & Z
- Machine related codes such as F, R & S
- Offset related codes such as D, H & T
- Program related codes such as G, N, O, P & Q