Common M-codes

Common M-codes

M-codes switch machine functions on and off. The ones in every program are M03, M04 and M05 for the spindle, M08 and M09 for coolant, M06 for a tool change, M00 and M01 for stops, and M30 to end the program and rewind. Low numbers are close to universal; higher ones depend on the machine builder.

The M-codes in every program

CodeNameWhat it does
M00Program stopStops the program until the operator presses cycle start.
M01Optional stopStops only when the Optional Stop switch is on.
M02End of programEnds the program. On many controls it does not rewind to the start.
M03Spindle on, clockwiseStarts the spindle forward (clockwise) at speed S.
M04Spindle on, counterclockwiseStarts the spindle in reverse (counterclockwise).
M05Spindle stopStops the spindle.
M06Tool changeChanges to the tool called by T.
M07Mist coolant onTurns on mist (or on some machines, through-spindle) coolant.
M08Flood coolant onTurns on flood coolant.
M09Coolant offTurns all coolant off.
M19Spindle orientationStops the spindle at a fixed angle.
M29Rigid tapping mode (Fanuc)Locks spindle rotation to the feed for the next tapping cycle.
M30End of program and rewindEnds the program and returns to the first line, ready for the next part.
M97Local subprogram call (Haas)On Haas, calls a subprogram at an N line inside the same program.
M98Subprogram callCalls another program as a subprogram.
M99Subprogram end / returnEnds a subprogram and returns to the calling program.

Where they sit in a program

M-codes follow the life of each tool. A typical order on a machining centre:

  1. T2 M06 loads the tool (M06).
  2. S1500 M03 starts the spindle clockwise (M03); M04 runs it the other way for left-hand tools.
  3. G43 H02 Z25. M08 turns flood coolant on with the approach move (M08).
  4. The cutting moves run.
  5. M09 and M05 switch coolant and spindle off before the next tool (M09, M05).
  6. M01 lets the operator check the first part tool by tool when Optional Stop is on (M01).
  7. M30 ends the program and rewinds for the next part (M30).

The pairs people confuse

  • M00 always stops; M01 stops only when the Optional Stop switch is on.
  • M02 ends the program; M30 ends it and rewinds, the normal choice for production.
  • M03 and M04: forward and reverse. A right-hand drill in M04 rubs and breaks.
  • M98 calls a subprogram; M99 returns from it.

For the G-codes these work alongside, see common G-codes and the full M-code list.

Quiz: common M-codes

Ten questions on the M-codes above.

Question 1 of 10Score 0

Mill and lathe: what does this code do?

M99

Keep going with saved progress and review of missed codes

More practice hubs

Frequently asked questions

What are the most common M-codes?
M00 (program stop), M01 (optional stop), M03 (spindle on, clockwise), M04 (spindle on, counterclockwise), M05 (spindle stop), M06 (tool change), M08 (flood coolant on), M09 (coolant off), M30 (end of program and rewind).
What is the difference between G-codes and M-codes?
G-codes tell the machine how to move: rapid or feed, arcs, units, offsets and cycles. M-codes switch machine functions on and off: spindle, coolant, tool change, program stops and subprograms.
Can there be more than one M-code on a line?
Many modern controls accept several M-codes on one line, but older ones and some machines allow only one. Writing one M-code per line is the safe habit until you know your control.
Why are some M-codes different on my machine?
The low numbers are close to universal. Above roughly M30, machine builders assign codes to their own options, such as chip conveyors, probes, pallet changers and door locks, so check the M-code list in your machine's manual.

G-Code Sprint is an educational practice tool only. It is not a CNC simulator, machine controller, safety manual, or replacement for instruction. Always follow your instructor, employer, machine manual, and shop procedures.

Free preview · no card Try G-Code Sprint