Table of Contents
ToggleWhat are M codes used for?
In CNC machining, M codes are used to control machine and miscellaneous functions.
This includes turning off and on features such as the machine spindle as well as coolant functions. They also control how the CNC reads and flows through the program.
M codes are the second most common codes used in CNC programming.Â
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.
For anyone new, be sure to check out our post on the first M codes to learn to make sure you start with the important stuff.
List of M Codes
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.
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.
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.
Turns the spindle on in the clockwise direction. This is the spindle direction used by most cutting tools.
Turns the spindle on in the counterclockwise direction.Â
Stops the machine spindle.
Swaps tools.
Turns on a coolant mist. Some machines treat it as coolant source 1 on.
Turns the coolant on to soak the workpiece. Some machines treat it as coolant source 2 on.
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.
Stops everything including the spindle, movement, coolant and will go back to the beginning of the program.
Starts a subprogram.
Starts a subprogram.
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 in CNC programming?
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Â