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
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.
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