Ultimate Guide to CNC M Codes

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.

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.

Learn more about the M00 code

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.

Learn more about the M01 code

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.

Learn more about the M02 code

Turns the spindle on in the clockwise direction. This is the spindle direction used by most cutting tools.

Learn more about the M03 code

Turns the spindle on in the counterclockwise direction. 

Learn more about the M04 code

M06 CNC M Code

M06 - Tool Change

Swaps tools.

Turns on a coolant mist. Some machines treat it as coolant source 1 on.

Learn more about the M07 code

Turns the coolant on to soak the workpiece. Some machines treat it as coolant source 2 on.

Learn more about the M08 code

Turns off all coolant sources.

Learn more about the M09 code

M19 CNC M Code

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.

Learn more about the M30 code

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 

Leave a Comment