G-codes command motion. M-codes handle the “miscellaneous” machine functions: turning the spindle and coolant on or off, changing tools, and ending the program. A beginner only needs a small set to start.

Spindle

  • M03: spindle on, clockwise (forward).
  • M04: spindle on, counterclockwise (reverse).
  • M05: spindle stop.

These three are worth drilling together. See M03 vs M04 vs M05 for the full breakdown.

Coolant

  • M08: coolant on.
  • M09: coolant off.

The core M-codes at a glance

CodeFunctionGroup
M03 / M04 / M05Spindle on CW / on CCW / stopSpindle
M08 / M09Coolant on / offCoolant
M06Tool change (with a T word)Tool
M00 / M01Program stop / optional stopProgram
M30Program end and rewindProgram

Tool change and program control

  • M06: tool change (usually with a T word, like T02 M06).
  • M00: program stop (always pauses).
  • M01: optional stop (pauses only if the switch is on).
  • M30: program end and rewind. This is how most programs finish.
T02 M06     (change to tool 2)
M03 S1500   (spindle on, clockwise, 1500 rpm)
M08         (coolant on)
...
M05         (spindle stop)
M09         (coolant off)
M30         (end and rewind)

How to remember them

As with any reference, reading the list is not the same as recalling it. Drill these as quick code-to-meaning questions and review the ones you miss, the same practice-first way you learn the common G-codes. The whole approach is laid out in beginner CNC code practice.

Bottom line

Learn spindle (M03, M04, M05), coolant (M08, M09), tool change (M06), the stops (M00, M01), and the end (M30). That set covers most beginner programs.

Sources

Frequently asked questions

What is the difference between M00 and M01?

M00 is a mandatory program stop: the machine always pauses there until you resume. M01 is an optional stop that only triggers when the optional-stop switch on the control is turned on.

What is the difference between M30 and M02?

Both end the program. M30 also rewinds it back to the start, which is the common modern choice, while M02 ends without the rewind. Most programs end with M30.

What is the best app to practice CNC M-codes?

For pure recall of what each M-code does, a free drill app like G-Code Sprint works well: it has a dedicated M-code mode that quizzes spindle, coolant, tool-change, and program codes and repeats the ones you miss. It is a study tool, not a controller, so always confirm against your machine’s manual.

G-Code Sprint is a study and practice tool only. Always follow your instructor, employer, machine manual, and shop safety procedures.