Skip to content

Miscellaneous functions · 76 codes

M-codes

M-codes switch machine functions on and off: spindle, coolant, tool change, stops or end of program. The basic ones are nearly the same everywhere; the rest are defined by each machine builder. Here are the common ones and the full list, each with its own reference page.

The most used M-codes

These appear in almost every program. Open any of them to see how it is used and which mistakes to avoid.

Full M-code list

Sorted by number, including each manufacturer's own codes. Each code links to its page.

Full M-code list
CodeWhat it doesMachine
M00/M01Mandatory / optional stopMill, Lathe, Mill-turn, Laser
M02End of programMill, Lathe, Mill-turn, Laser
M03/M04/M05Spindle controlMill, Lathe, Mill-turn
M06Tool changeMill, Mill-turn
M07Mist / auxiliary coolantMill, Lathe, Mill-turn
M08/M09CoolantMill, Lathe, Mill-turn
DN M10/M11Plate or clamp open/close DN/DoosanLathe, Mill-turn
M10/M11Clamping open/closeLathe, Mill-turn
Okuma M10-M27Axis clamps and barriersMill, Lathe, Mill-turn
M12/M13Air blastMill, Lathe, Mill-turn
M13/M14Spindle with coolant / combined functionMill, Lathe, Mill-turn
M14/M15Spindle brake / C-axisLathe, Mill-turn
M17/M18Turret indexingLathe, Mill-turn
M19Spindle orientationMill, Lathe, Mill-turn
M21/M22Tailstock advance/retractLathe, Mill-turn
M23/M24Threaded chamfer exitLathe, Mill-turn
M25-M29Bar feeder, parts catcher and lathe auxiliariesLathe, Mill-turn
M29Rigid thread preparationMill, Mill-turn
M30End of programMill, Lathe, Mill-turn, Laser
DN M31/M32DN/Doosan chip conveyorMill, Lathe, Mill-turn
M31/M32Chuck bypass / lathe auxiliaryLathe, Mill-turn
M31/M33Haas chip conveyorMill, Lathe, Mill-turn
M35/M36/M37Parts catcherLathe, Mill-turn
M37/M38Conveyor or auxiliary functionMill, Lathe, Mill-turn
M38/M39Spindle speed variationLathe, Mill-turn
M41/M42Low/high spindle gear rangeMill, Lathe, Mill-turn
M43/M44Tool setter / turret lockLathe, Mill-turn
M48/M49Enable/disable overrideMill, Lathe, Mill-turn
Okuma M50-M54Coolant per tool and return cycleMill, Mill-turn
M51-M56/M61-M66Integrated M-code relaysMill, Lathe, Mill-turn, Laser
M52/M53Adaptive feed control / feed stopMill, Lathe, Mill-turn
M53-M56Steady rest and tailstock clamp/unclampLathe, Mill-turn
Okuma M55/M56Tailstock retract/advanceLathe, Mill-turn
Okuma M58/M59Low/high clamping pressureLathe, Mill-turn
M60Pallet changeMill, Mill-turn
M62-M65Auxiliary outputs / PLCMill, Lathe, Mill-turn, Laser
M68/M69Hydraulics / auxiliary outputLathe, Mill-turn
M70/M71Mirror / cancel mirror (some Fanuc)Mill, Mill-turn
Okuma M73-M75Threading patternsLathe, Mill-turn
M78/M79Skip signal alarmsMill, Lathe, Mill-turn
M80/M81APC pallet changerMill, Mill-turn
Mazak M81-M84Piece/tool measurementLathe, Mill-turn
Okuma M83/M84Chuck clamp/unclampLathe, Mill-turn
Haas M85/M86Door, clamping or optional interlockMill, Lathe, Mill-turn
Haas M88/M89Coolant through Haas spindleMill, Mill-turn
Mazak M90/M91Mazak main chuck clampingLathe, Mill-turn
M94/M95/M96Mirror image via M-codeMill, Mill-turn
Mazak M96/M198/M199Macro and EIA/Mazatrol switchingMill, Lathe, Mill-turn
Haas M97Haas local subprogramMill, Lathe, Mill-turn
M97Local subprogram / part counterMill, Lathe, Mill-turn
M98/M99Subprogram / returnMill, Lathe, Mill-turn
Haas M109Wait at spindle speedMill, Lathe, Mill-turn
Mazak M110/M111Mazak automatic door controlMill, Lathe, Mill-turn
Okuma M116/M117Safety barrier / chuck barrierLathe, Mill-turn
M121-M129Relays with M-FinMill, Lathe, Mill-turn
M130/M131Show/cancel mediaMill, Lathe, Mill-turn
M133/M134/M135motorized lathe toolLathe, Mill-turn
Mazak M150-M153Integrex robot, air blast and coolantLathe, Mill-turn
Okuma M152/M153/M168/M169Powered tool and C axisLathe, Mill-turn
M154/M155Engage/disengage C axisLathe, Mill-turn
M158/M159Mist extractorMill, Lathe, Mill-turn
Okuma M191/M192Powered tool orientationLathe, Mill-turn
M198External subprogram call (USB/card)Mill, Lathe, Mill-turn
Haas M199Automatic start next programMill, Lathe, Mill-turn
Mazak M200-M205Lathe/mill and live tool modeLathe, Mill-turn
Okuma M201-M220Okuma M-code macrosMill, Lathe, Mill-turn
Mazak M210-M283Expanded Integrex AutomationLathe, Mill-turn
Okuma M211-M214Keyway cuttingLathe, Mill-turn
M299/M300APL/robot and custom sequenceMill, Lathe, Mill-turn
M334/M335P-Cool settingMill, Mill-turn
M373/M374Tool Air BlastMill, Mill-turn
M388/M389Advanced through-spindle coolantMill, Mill-turn
DMG Mori M-codesDMG Mori auxiliary functionsMill, Lathe, Mill-turn
Hermle M-codesHermle auxiliary functionsMill, Mill-turn
Mazak M-codesMazak auxiliary M-codesMill, Lathe, Mill-turn
Okuma M-codesOkuma auxiliary functionsMill, Lathe, Mill-turn

01The basic M-codes are almost universal

M03, M04 and M05 run the spindle clockwise, counter-clockwise or stop it; M08 and M09 switch coolant on and off; M06 changes the tool on a mill; M00 stops the program and M01 only stops if the operator enables optional stop; M30 ends the program and rewinds, and M98/M99 call and close subprograms. That covers most programs.

02Many M-codes are defined by the machine builder

Beyond the basics, the number is assigned by the machine builder, not the control: the same M-code may open the chuck on one lathe, move the tailstock on another or not exist on a third. Haas, Mazak, Okuma, DN Solutions, DMG Mori and Hermle publish their own tables. Before using an M-code you do not know, look it up in your machine manual, not the control manual.

03One M per block, and when it acts

Many controls accept only one M-code per block unless a parameter allows more, so the safe habit is one per line. Depending on the machine, an M-code may also act at the start of the block (before the move) or at the end: that is why it is good practice to program M05, M09 or the tool change in a block of their own, with the tool already retracted.

04M02 and M30 are not the same

Both end the program, but M30 also rewinds to the start for the next part, while on many controls M02 stays at the end. Production programs use M30; M02 is mostly found in older programs.

Frequently asked questions

What is an M-code?

It is a miscellaneous function in a CNC program: it switches something on the machine on or off, such as the spindle, coolant, tool change, a stop or the end of program. It does not move the axes by itself.

What does M03 do and how is it different from M04?

M03 turns the spindle clockwise and M04 counter-clockwise, at the rpm set by S. M05 stops it.

What is the difference between M00 and M01?

M00 always stops the program until the operator presses cycle start; M01 only stops if optional stop is enabled on the panel. M01 is used to inspect parts without stopping every cycle.

Why does an M-code not work the same on two machines?

Because, apart from the basic ones, each builder assigns its own numbers to functions such as the chuck, tailstock or bar feeder. Check your machine manual before using it.

General reference: syntax and meaning change with the control, the machine builder and machine parameters. Check the official manual before running a program. Last updated: