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
| Code | Name | What it does |
|---|---|---|
M00 | Program stop | Stops the program until the operator presses cycle start. |
M01 | Optional stop | Stops only when the Optional Stop switch is on. |
M02 | End of program | Ends the program. On many controls it does not rewind to the start. |
M03 | Spindle on, clockwise | Starts the spindle forward (clockwise) at speed S. |
M04 | Spindle on, counterclockwise | Starts the spindle in reverse (counterclockwise). |
M05 | Spindle stop | Stops the spindle. |
M06 | Tool change | Changes to the tool called by T. |
M07 | Mist coolant on | Turns on mist (or on some machines, through-spindle) coolant. |
M08 | Flood coolant on | Turns on flood coolant. |
M09 | Coolant off | Turns all coolant off. |
M19 | Spindle orientation | Stops the spindle at a fixed angle. |
M29 | Rigid tapping mode (Fanuc) | Locks spindle rotation to the feed for the next tapping cycle. |
M30 | End of program and rewind | Ends the program and returns to the first line, ready for the next part. |
M97 | Local subprogram call (Haas) | On Haas, calls a subprogram at an N line inside the same program. |
M98 | Subprogram call | Calls another program as a subprogram. |
M99 | Subprogram end / return | Ends 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:
T2 M06loads the tool (M06).S1500 M03starts the spindle clockwise (M03); M04 runs it the other way for left-hand tools.G43 H02 Z25. M08turns flood coolant on with the approach move (M08).- The cutting moves run.
M09andM05switch coolant and spindle off before the next tool (M09, M05).M01lets the operator check the first part tool by tool when Optional Stop is on (M01).M30ends 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
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.