M-code reference

CNC M-code list

M-codes are the miscellaneous commands of a CNC program: they switch machine functions such as the spindle, coolant, tool changes and program stops. This list covers the 16 M-codes a beginner meets most. Many M-codes above M30 are set by the machine builder, so always check your machine's own M-code list.

Program control

Each acts only on its own line.

CodeNameWhat it doesMachine
M00 Program stop Stops the program until the operator presses cycle start. Mill and lathe
M01 Optional stop Stops only when the Optional Stop switch is on. Mill and lathe
M02 End of program Ends the program. On many controls it does not rewind to the start. Mill and lathe
M30 End of program and rewind Ends the program and returns to the first line, ready for the next part. Mill and lathe
M97 Local subprogram call (Haas) On Haas, calls a subprogram at an N line inside the same program. Mill and lathe
M98 Subprogram call Calls another program as a subprogram. Mill and lathe
M99 Subprogram end / return Ends a subprogram and returns to the calling program. Mill and lathe

Spindle

CodeNameWhat it doesMachine
M03 Spindle on, clockwise Starts the spindle forward (clockwise) at speed S. Mill and lathe
M04 Spindle on, counterclockwise Starts the spindle in reverse (counterclockwise). Mill and lathe
M05 Spindle stop Stops the spindle. Mill and lathe
M19 Spindle orientation Stops the spindle at a fixed angle. Mill and lathe
M29 Rigid tapping mode (Fanuc) Locks spindle rotation to the feed for the next tapping cycle. Mill and lathe

Coolant

Modal: one stays active until another from this group replaces it.

CodeNameWhat it doesMachine
M07 Mist coolant on Turns on mist (or on some machines, through-spindle) coolant. Mill and lathe
M08 Flood coolant on Turns on flood coolant. Mill and lathe
M09 Coolant off Turns all coolant off. Mill and lathe

Tool

Each acts only on its own line.

CodeNameWhat it doesMachine
M06 Tool change Changes to the tool called by T. Mill

Meanings follow the common Fanuc-style standard shared by Haas, Okuma (EIA mode), Mitsubishi, LinuxCNC and most other controls; lathe meanings use Fanuc G-code system A. Check the manual for your control before running a program.

More practice hubs

Frequently asked questions

What is the difference between M00, M01, M02 and M30?
M00 always stops the program until cycle start is pressed. M01 stops only when Optional Stop is on. M02 ends the program; M30 ends it and rewinds to the start, ready for the next part.
Which M-codes control the spindle and coolant?
M03 starts the spindle clockwise, M04 counterclockwise and M05 stops it. M08 turns flood coolant on, M07 mist coolant on most machines, and M09 turns coolant off.
Are M-codes the same on every machine?
The low numbers (M00 to M09, M30, M98, M99) are close to universal. Higher numbers are assigned by each machine builder for options such as chip conveyors, probes and pallet changers, so they vary from machine to machine.

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