# CNC M-Code Reference Table

> Source: https://netray.co/tools/cnc-m-code-reference-table
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

A searchable table of common CNC M-codes for spindle, coolant, tool change, program control and subprograms, with practical notes.

## Category

manufacturing

## Industry

Machine Shops

## Audience

- CNC machinist
- CNC programmer
- Manufacturing engineer

## Tool

**Kind:** worksheet

**Mode:** reference

**Columns:**

#### M-code

**Key:** code

**Type:** text

#### Function

**Key:** function

**Type:** text

#### Group

**Key:** group

**Type:** text

#### Mill / Lathe

**Key:** machine

**Type:** text

#### Notes

**Key:** notes

**Type:** text

**Rows:**

**Code:** M00

**Function:** Program stop

**Group:** Program control

**Machine:** Both

**Notes:** Stops until the operator presses cycle start. Spindle and coolant may stop depending on the control.

**Code:** M01

**Function:** Optional stop

**Group:** Program control

**Machine:** Both

**Notes:** Stops only if the optional stop switch is on.

**Code:** M02

**Function:** End of program

**Group:** Program control

**Machine:** Both

**Notes:** Ends the program. Does not always rewind.

**Code:** M03

**Function:** Spindle on, clockwise

**Group:** Spindle

**Machine:** Both

**Notes:** Needs an S word. Normal for right-hand cutting tools.

**Code:** M04

**Function:** Spindle on, counterclockwise

**Group:** Spindle

**Machine:** Both

**Notes:** For left-hand tools and some tapping setups.

**Code:** M05

**Function:** Spindle stop

**Group:** Spindle

**Machine:** Both

**Notes:** Program before an operator interaction or a tool change on some controls.

**Code:** M06

**Function:** Tool change

**Group:** Tool

**Machine:** Mill

**Notes:** Select the tool with T, then M06 to swap. Often preceded by a move to the tool change position.

**Code:** M07

**Function:** Mist coolant on

**Group:** Coolant

**Machine:** Both

**Notes:** Option on many machines.

**Code:** M08

**Function:** Flood coolant on

**Group:** Coolant

**Machine:** Both

**Notes:** Standard flood coolant.

**Code:** M09

**Function:** Coolant off

**Group:** Coolant

**Machine:** Both

**Notes:** Turns off M07 and M08.

**Code:** M10

**Function:** Clamp / chuck or axis clamp (varies)

**Group:** Machine option

**Machine:** Both

**Notes:** Meaning varies by builder. Check the manual.

**Code:** M11

**Function:** Unclamp (varies)

**Group:** Machine option

**Machine:** Both

**Notes:** Meaning varies by builder.

**Code:** M13

**Function:** Spindle clockwise with coolant on

**Group:** Spindle

**Machine:** Both

**Notes:** ISO combined code, not on all controls.

**Code:** M14

**Function:** Spindle counterclockwise with coolant on

**Group:** Spindle

**Machine:** Both

**Notes:** ISO combined code, not on all controls.

**Code:** M19

**Function:** Spindle orient

**Group:** Spindle

**Machine:** Both

**Notes:** Stops the spindle at a fixed angle. Used for boring bar shift and tool change.

**Code:** M29

**Function:** Rigid tapping mode

**Group:** Spindle

**Machine:** Mill

**Notes:** Fanuc-style. Placed before G84 so spindle and Z are synchronized.

**Code:** M30

**Function:** End of program and rewind

**Group:** Program control

**Machine:** Both

**Notes:** Resets the program to the start. Standard end of a program.

**Code:** M41

**Function:** Spindle low gear range

**Group:** Spindle

**Machine:** Lathe

**Notes:** Gear range codes M41 to M44 on many Fanuc-style lathes.

**Code:** M42

**Function:** Spindle second gear range

**Group:** Spindle

**Machine:** Lathe

**Notes:** Range depends on the machine.

**Code:** M43

**Function:** Spindle third gear range

**Group:** Spindle

**Machine:** Lathe

**Notes:** Range depends on the machine.

**Code:** M44

**Function:** Spindle fourth gear range

**Group:** Spindle

**Machine:** Lathe

**Notes:** Range depends on the machine.

**Code:** M48

**Function:** Enable feed and speed override

**Group:** Override

**Machine:** Both

**Notes:** Allows operator overrides after M49.

**Code:** M49

**Function:** Disable feed and speed override

**Group:** Override

**Machine:** Both

**Notes:** Common during threading or tapping on some controls.

**Code:** M97

**Function:** Local subprogram call (some controls)

**Group:** Subprogram

**Machine:** Both

**Notes:** Haas-style call to a label in the same program.

**Code:** M98

**Function:** Subprogram call

**Group:** Subprogram

**Machine:** Both

**Notes:** Call with P for program number, and L or Q for repeat count, depending on control.

**Code:** M99

**Function:** Subprogram return / program loop

**Group:** Subprogram

**Machine:** Both

**Notes:** Returns to the calling program. At the end of a main program it can loop.

**Notes:** 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.

## Content

**Intro:** 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.

**Sections:**

#### How to use the table

**Body:** 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

**Body:** 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.

**Bullets:**

- Program control: M00, M01, M02, M30
- Spindle: M03, M04, M05, M19
- Coolant: M07, M08, M09
- Tool and subprograms: M06, M98, M99

#### M02 versus M30

**Body:** 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

**Body:** 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.

**Cta:** 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.

**Faq:**

#### What is the difference between M02 and M30?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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?

**Answer:** 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.

## Search terms

m code list, cnc m codes, m code reference, m03 m04 m05, m06 tool change, m30 vs m02, fanuc m codes, m code cheat sheet

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
