CNC M-Code Reference Table
M-codes are the miscellaneous machine functions: spindle, coolant, tool change and program flow. This table lists the ones programmers use daily and flags the ones that change from machine to machine.
| M-code | Function | Group | Mill / Lathe | Notes |
|---|---|---|---|---|
M00 | Program stop | Program control | Both | Stops until the operator presses cycle start. Spindle and coolant may stop depending on the control. |
M01 | Optional stop | Program control | Both | Stops only if the optional stop switch is on. |
M02 | End of program | Program control | Both | Ends the program. Does not always rewind. |
M03 | Spindle on, clockwise | Spindle | Both | Needs an S word. Normal for right-hand cutting tools. |
M04 | Spindle on, counterclockwise | Spindle | Both | For left-hand tools and some tapping setups. |
M05 | Spindle stop | Spindle | Both | Program before an operator interaction or a tool change on some controls. |
M06 | Tool change | Tool | Mill | Select the tool with T, then M06 to swap. Often preceded by a move to the tool change position. |
M07 | Mist coolant on | Coolant | Both | Option on many machines. |
M08 | Flood coolant on | Coolant | Both | Standard flood coolant. |
M09 | Coolant off | Coolant | Both | Turns off M07 and M08. |
M10 | Clamp / chuck or axis clamp (varies) | Machine option | Both | Meaning varies by builder. Check the manual. |
M11 | Unclamp (varies) | Machine option | Both | Meaning varies by builder. |
M13 | Spindle clockwise with coolant on | Spindle | Both | ISO combined code, not on all controls. |
M14 | Spindle counterclockwise with coolant on | Spindle | Both | ISO combined code, not on all controls. |
M19 | Spindle orient | Spindle | Both | Stops the spindle at a fixed angle. Used for boring bar shift and tool change. |
M29 | Rigid tapping mode | Spindle | Mill | Fanuc-style. Placed before G84 so spindle and Z are synchronized. |
M30 | End of program and rewind | Program control | Both | Resets the program to the start. Standard end of a program. |
M41 | Spindle low gear range | Spindle | Lathe | Gear range codes M41 to M44 on many Fanuc-style lathes. |
M42 | Spindle second gear range | Spindle | Lathe | Range depends on the machine. |
M43 | Spindle third gear range | Spindle | Lathe | Range depends on the machine. |
M44 | Spindle fourth gear range | Spindle | Lathe | Range depends on the machine. |
M48 | Enable feed and speed override | Override | Both | Allows operator overrides after M49. |
M49 | Disable feed and speed override | Override | Both | Common during threading or tapping on some controls. |
M97 | Local subprogram call (some controls) | Subprogram | Both | Haas-style call to a label in the same program. |
M98 | Subprogram call | Subprogram | Both | Call with P for program number, and L or Q for repeat count, depending on control. |
M99 | Subprogram return / program loop | Subprogram | Both | Returns to the calling program. At the end of a main program it can loop. |
M-codes are defined mostly by the machine builder, not by a universal standard. Codes shown follow common Fanuc and Haas-style usage. Verify every code in your machine's documentation, especially M10 to M19 and options like through-spindle coolant, chip conveyors and pallet changers.
Link CNC program governance to ERP records
Optional: we can discuss how program revisions and machine-specific data could be tied to part and routing records.
Optional. The tool and every export work without this. No spam.
How to use the table
Search by code or by function, for example M08, coolant or subprogram. Each row gives the function, its group, whether it applies to a mill, lathe or both, and a note on common behavior. Export it to Excel or PDF as a desk reference or to add machine-specific codes for your own shop. Because M-codes are largely set by the builder, add your machine's own columns for options like pallet change, parts catcher and through-spindle coolant.
Which M-codes are standard
A core group is nearly universal: M00 and M01 for stops, M02 and M30 for program end, M03, M04 and M05 for spindle, M06 for tool change, M08 and M09 for coolant, and M98 and M99 for subprograms. Beyond that the numbers are assigned by the control or machine builder. M10 and M11, for example, clamp and unclamp on some machines and mean other things on others. Machine builders also add numbered codes for options such as probes, pallets and bar feeders.
- Program control: M00, M01, M02, M30
- Spindle: M03, M04, M05, M19
- Coolant: M07, M08, M09
- Tool and subprograms: M06, M98, M99
M02 versus M30
Both end a program, but M30 also rewinds it to the first block so the next cycle start begins from the top, while M02 may stop at the end with the program pointer unchanged on some controls. Most shops standardize on M30 as the last line of every main program. M99 behaves differently: at the end of a subprogram it returns to the calling program, and at the end of a main program it can loop the program back to the start, which can be used for bar-fed production.
Common mistakes
A frequent crash cause is forgetting M05 or M09 before a manual operation, or calling M06 without moving to a safe position first. Another is relying on a code from one machine on another: M19 orientation, M29 rigid tapping and clamp codes all differ. Also remember that an M-code in a block with a motion command may execute before, with or after the move depending on the code and the control, so put critical spindle commands on their own lines.
Frequently Asked Questions
What is the difference between M02 and M30?
Both end the program. M30 ends it and returns to the beginning of the program so it is ready for the next part, while M02 simply ends it and may not rewind. Most shops use M30 on every main program.
What do M03, M04 and M05 do?
M03 starts the spindle clockwise, M04 starts it counterclockwise and M05 stops it. M03 and M04 need a spindle speed S word, either in the same block or earlier. Most right-hand cutting tools run under M03.
Are M-codes the same on all CNC machines?
Only the common ones. Stops, spindle, coolant and program end are widely consistent, but many M-codes are assigned by the machine builder for options and differ. Always check your machine's manual before using unfamiliar codes.
What does M98 do?
M98 calls a subprogram, using P for the program number and an optional repeat count depending on the control. The subprogram ends with M99 to return. It is used for repeated features, multiple parts on a fixture and long toolpath files.
If machine-specific code lists and post-processor settings live in individual programmers' heads, Netray can help capture them against machine and part records for governance.
Related Tools
CNC G-Code Reference Table
A searchable table of common G-codes for milling and turning with their function, group and practical notes.
Discrete ManufacturingCNC Speeds and Feeds Calculator
Turn a surface speed and chip load into spindle RPM and table feed for any end mill, capped at your machine's maximum RPM.
Discrete ManufacturingCNC Chip Load Reference Worksheet
A printable chip load starting-point chart for carbide end mills with a fill-in record for the cutting data you finally prove out.
Costing & FinanceCNC Machining Cost Calculator
Build a per part CNC price from setup hours, cycle time, shop rate, material, tooling, outside processing, scrap and margin.