M codes in a Machine à commande numérique are auxiliary control instructions that manage non-cutting machine functions. They handle spindle start and stop, tool changes, coolant activation, program stops, and end-of-cycle commands. Unlike G codes, which govern geometric motion and cutting parameters, M codes operate the machine’s mechanical and electrical systems. Every program you run on a CNC machining center or lathe depends on M codes to sequence operations in the right order. A missing or misplaced code can trigger a tool crash, dry cutting, or a full program lockout. Knowing which M codes your controller supports is the first step toward writing clean, reliable programs.
Most operators learn M codes by rote, but one missing command can halt a production run or damage a tool. If you are writing, reviewing, or troubleshooting CNC part programming for a manufacturing job, knowing exactly what each M code triggers and when it should fire saves time and protects your parts.
The 8 M Codes Every Operator Should Know
Not every M code from M00 to M99 is used on every machine. The eight below appear in the majority of Fabrication par commande numérique (CNC) environments. Exact behavior can vary by controller brand such as Fanuc, Siemens, or Haas, so verify against your machine’s program manual before writing a new program.
| Code M | Fonction | Utilisation type |
|---|---|---|
| M00 | Arrêt du programme | Hold for manual inspection or setup |
| M03 | Spindle on, clockwise | Face milling, drilling, turning |
| M04 | Spindle on, counter-clockwise | Left-hand cutting, tapping |
| M05 | Arrêt de la broche | Between setups,manual work |
| M06 | Changement d'outil | Multi-tool programs, auto tool changer |
| M08 | Liquide de refroidissement activé | Flood or mist coolant |
| M09 | Refroidissement désactivé | End of wet operation |
| M30 | Program end and reset | Return to origin, stop cycle |
Your controller may map some of these differently. M08 might activate flood coolant on one machine and mist on another. A program that runs cleanly on a Haas can behave differently on a Fanuc unless you confirm the M-code mapping first. When in doubt, run a dry cycle in single-block mode and watch each command fire.
How M Codes Fit Inside a CNC Program
M codes appear on their own block or in parentheses at the end of a G-code line. The controller executes them in sequence as the program runs. A few structural rules matter for every operator:

M03 and M04 are cancelling codes: issuing one stops the other.
M08 and M09 work the same way; one turns coolant on, the other off.
M30 auto-rewinds the program to the beginning and resets the controller.
M99 returns from a subroutine back to the main program.
When you are sequencing a multi-tool usinage CNC sur mesure job, the order of M codes matters. A coolant-on command that fires after the tool has already cleared the workpiece wastes fluid and cycle time. YPMFG engineering reviews M-code sequencing when quoting complex multi-operation parts so the program flows without idle blocks or unnecessary machine state changes.
Mistakes That Cost You Downtime
A few M-code errors show up in nearly every shop that runs high-mix milling or turning work:
Forgetting M05 before a manual tool change, leaving the spindle spinning while an operator works.
Using M30 when you actually need a controlled M00 stop mid-program for in-process inspection.

Mismatching M-code numbers between a CAD/CAM simulator and the actual contrôleur CNC on the floor.
Porting a milling M-code sequence to a lathe without adjusting for turret index and spindle differences.
Each of these is a CNC troubleshooting scenario that can idle a machine for the rest of the shift. Before you hit cycle start on a new part, run the program in single-block mode and confirm that each M-code fires in the order you expect. If the sequence looks wrong, fix it in the program file, not on the floor.
Common Questions About M Codes in CNC Machines
Are M codes the same on every CNC machine?
No. The ISO 6983 standard defines baseline M codes, but each manufacturer extends the list. A Haas controller may assign M42 to turret index on a Tour à commande numérique, while Fanuc uses M42 for spindle stop. Always check your machine’s M-code table before porting a program from one shop to another.
Can M codes be combined on one block?
Most controllers allow one M code per block. Stacking M03 and M08 on the same line as a G01 move works on many machines, but some only read the last M code in that block. Confirm your controller’s programming manual before combining multiple M codes in a single line.
What happens if I skip M05 before M06?
On machines where M06 implicitly stops the spindle, nothing bad occurs. On others, the spindle keeps rotating during the tool change, which can damage the tool changer or the workpiece. The safe practice is to include M05 before every M06 in your program, even if your current controller handles it automatically.
Do M codes affect CNC part quality?
Indirectly, yes. A coolant timing error, such as M08 firing too late, can cause thermal distortion on thin-walled parts. A missing M30 may leave the machine in a state where the next job starts mid-program. Proper M-code discipline protects CNC part quality and repeat-to-repeat accuracy across a production run.
How do I find the M-code list for my machine?
The full M-code table is in the machine’s operator or programming manual, usually in an appendix. If you no longer have that manual, the controller OEM publishes a machine-specific document. You can also request one from your machine supplier or from YPMFG if you are evaluating a new CNC setup for a project.
Prendre une meilleure décision à long terme
Before you lock a Usinage CNC program for production, treat the M-code sequence the same way you treat your tool paths. One missed coolant-off or a duplicated program-end can idle the machine for the rest of the shift.
If you are setting up a new part, reviewing a program, or checking how your CNC mechanical parts flow through the cell, you can send your G-code and M-code list to YPMFG for an engineering review. They will flag sequencing issues, confirm controller compatibility, and suggest changes that reduce cycle time without adding risk to your tooling.




