Quick answer:
M codes on a CNC lathe are auxiliary commands that control machine functions outside of tool cutting. They trigger actions such as spindle start, coolant on or off, tool changes, and program termination. M codes do not define tool path geometry—that is the role of G codes, which handle feed rates, arc moves, and axis positioning. Because M code assignments vary by controller manufacturer and machine model,operators should always cross-check against their specific machine manual before running a new program.
If you are writing or troubleshooting a CNC lathe program, unclear M code behavior is one of the most common sources of cycle errors on the shop floor. A single wrong code can stop the machine mid-cut, flood the way with coolant, or skip a critical tool change. This guide covers the most frequently used M codes, how they are grouped, and what to verify when a program misbehaves. YPMFG supports machined component projects where correct M code sequencing directly affects part quality and production cycle time.
What M Codes Actually Do on a CNC Lathe
M codes are non-geometric commands. They tell the controller to activate or deactivate auxiliary machine functions rather than move the tool across axes. On a typical CNC lathe, that covers four main categories:
Spindle control: start, stop, rotation direction, and speed
Coolant and flood control: activating and shutting down cutting fluid
Tool turret changes and selection

Program flow: end, optional stop, subroutine calls, and returns
Each M code sits on its own block line, usually paired with G, X, Z, S, or T addresses. Stacking multiple M codes in one block is possible on some controllers but introduces timing risk. Keep one M code per block unless your machine documentation explicitly supports multi-code blocks.
Most Common CNC Lathe M Codes
The table below lists the M codes you will encounter most often in a standard turning program:
| M Code | Function | Typical Use |
|---|---|---|
| M00 | Program stop | Operator pauses the cycle |
| M01 | Optional stop | Pauses only if hold switch is on |
| M02 | End of program | Stops without controller reset |
| M03 | Spindle start, CCW | Begins counter-clockwise cutting |
| M04 | Spindle start, CW | Begins clockwise cutting |
| M05 | Spindle stop | Halts all spindle rotation |
| M08 | Coolant on | Activates flood or mist |
| M09 | Coolant off | Shuts down cutting fluid |
| M10 | Work clamp on | Secures the fixture |
| M11 | Work clamp off | Releases the fixture |
| M30 | Program end + reset | Returns to home position |
| M98 | Subroutine call | Repeats a block sequence |
| M99 | Subroutine return | Jumps back to calling block |
M03 and M04 are the two most critical codes in any turning program. Choosing the wrong rotation direction can damage the tool or ruin a finished surface. M30 and M02 are frequently confused: M30 resets the controller state, while M02 simply halts execution. For batch production runs, M30 is typically the safer closing code because it automatically prepares the machine for the next part.
M Code Groups and Machine-Specific Variations
No two controllers use an identical M code table. FANUC, Siemens, Haas, and Mazak each define their own M code assignments. For instance, M08 for coolant on is nearly universal across brands, but M10 through M19 can mean completely different actions depending on the machine builder. Some lathes use M10 for a work clamp, while others assign it to a fixture light or a conveyor stop signal.
Before writing or editing a program, confirm three things:

Which controller platform is installed on your lathe
The full M code list from the machine-specific operator manual
Whether any user-defined codes in the M100–M199 range are configured for automation or custom fixture control
YPMFG engineering team reviews CNC program M code sequences when evaluating custom part projects, flagging sequencing conflicts, missing coolant pairs, or subroutine errors before the program reaches the shop floor.
Common Questions About CNC Lathe M Codes
Can I use multiple M codes in one program block?
Some controllers allow it, but each M code triggers a separate machine action. Stack them only when the documentation explicitly supports multi-code blocks. Otherwise, place each M code on its own line to avoid timing conflicts or missed actions.
What is the difference between M02 and M30?
M02 ends the program without resetting the controller state. M30 ends the program and resets the controller to its initial position. For automated batch production, M30 is preferred because it prepares the machine for the next cycle automatically.
Does M01 behave the same as M00?
M01 is an optional stop. It pauses the cycle only if the operator has enabled the optional hold switch on the control panel. M00 always stops regardless of switch position. Use M01 at inspection points where operator intervention is needed only sometimes.
What happens if I forget M09 after a cutting pass?
Coolant continues running into the next operation or into the program end. On a lathe, this wastes cutting fluid and can interfere with workholding or the next tool change. Always pair M08 and M09 before moving to the next step in the program.
Are M codes identical on a CNC mill?
The underlying concept is the same, but specific assignments differ by machine type. A lathe M code list will not match a milling machine list one-to-one. Check each machine’s documentation before transferring code between different setups.
Getting the M Code Sequence Right for Your Job
Correct M code sequencing protects your cycle time, part quality, and overall machine safety. If you are developing or modifying a program for a CNC lathe and are uncertain whether your M code logic will cause unexpected stops, coolant conflicts, or turret errors, send your draft program to YPMFG for an engineering review. The team can verify controller compatibility, flag sequencing gaps, and recommend practical fixes before the code runs on your production floor.





