CNC M-codes are commands used in CNC programming to control machine functions that support the actual cutting process. While G-codes mainly define tool movement, positioning, interpolation, and machining cycles, M-codes typically control functions such as the spindle, coolant, tool changer, program stops, pallets, clamps, and other machine accessories.
Some of the most commonly encountered CNC M codes include M03 for clockwise spindle rotation, M05 for spindle stop, M06 for tool change, M08 for coolant on, M09 for coolant off, and M30 for ending and resetting a CNC program.
Understanding these commands is important for machinists, CNC programmers, manufacturing engineers, and designers working with automated machining equipment. However, not every M-code has exactly the same function on every CNC machine. The controller, machine builder, and installed accessories can all affect how an M-code behaves.
This guide from Tuofa CNC Germania explains the most common CNC M-codes, how they work with G-code, and how they are used during real CNC milling and turning operations.
What Is an M-Code in CNC Programming?
An M-code is a CNC programming command used primarily to activate, deactivate, or control auxiliary machine functions. M is commonly associated with miscellaneous or machine functions, although the exact terminology may differ between controller documentation.
A typical M-code consists of the letter M followed by a number, such as:
- M03 – Start the spindle clockwise
- M05 – Stop the spindle
- M06 – Perform a tool change
- M08 – Turn flood coolant on
- M09 – Turn coolant off
- M30 – End and reset the CNC program
M-codes generally do not tell the cutting tool where to move in X, Y, or Z. Instead, they control the machine conditions required to perform machining safely and efficiently.
A simple way to understand the difference is:
G-code tells the CNC machine where and how the tool should move, while M-code tells the machine which supporting functions should operate.
Depending on the machine, M-codes may control the spindle, coolant system, automatic tool changer, chuck, clamps, pallets, gear ranges, subprograms, doors, chip conveyors, or other auxiliary equipment.
CNC M-Codes List and Functions
The following CNC M code list includes commonly used commands. These meanings are common on many CNC controls, particularly controls influenced by FANUC-style programming, but they should not be treated as universal. Always check the programming manual for the actual machine before running unfamiliar code.
Program Control M-Codes
M00 – Program Stop
M00 stops execution of the CNC program. Machining normally remains stopped until the operator resumes the cycle. It may be used for inspection, manual adjustment, chip removal, or another operation requiring operator attention.
M01 – Optional Stop
M01 works similarly to M00, but the stop is normally executed only when the machine’s optional-stop function is enabled. This is useful when inspection or operator intervention is required only under certain production conditions.
M02 – End of Program
M02 is used on many controls to indicate the end of a CNC program. Its exact end-of-program behavior can differ from M30 depending on the controller.
M30 – End Program and Reset
M30 is one of the most common ways to end a machining program. On many CNC controls, it ends the program and resets or rewinds program execution so the program is ready for another cycle.
Spindle Control M-Codes
M03 – Spindle Clockwise
M03 starts the spindle rotating clockwise. Spindle speed is normally specified separately with an S command.
S3000 M03
In this example, S3000 specifies a spindle speed of 3000 RPM, while M03 commands clockwise spindle rotation.
M04 – Spindle Counterclockwise
M04 starts spindle rotation in the opposite direction. It is used when the machining operation or tooling requires counterclockwise spindle rotation.
M05 – Spindle Stop
M05 stops spindle rotation. It is commonly used before tool changes, at the end of machining operations, or before another machine function that requires the spindle to stop.
Tool Change M-Code
M06 – Tool Change
M06 commonly initiates an automatic tool change on CNC machining centers. It is normally used with a T command specifying the required tool.
T03 M06
T03 typically identifies tool number 3, while M06 tells the machine to perform the tool-change operation.
Tool-change sequences vary between CNC machines. Some machines automatically move to a tool-change position, while others may require additional positioning or machine-specific programming.
Coolant M-Codes
M07 – Mist Coolant On
M07 commonly activates a mist coolant system where supported.
M08 – Flood Coolant On
M08 commonly activates flood coolant. Flood coolant can help control cutting temperature, lubricate the cutting zone, and remove chips during machining.
M09 – Coolant Off
M09 normally turns coolant off. It is frequently programmed before tool changes and near the end of a machining cycle.
Other Common CNC M-Codes
Other M-codes that may appear on CNC equipment include:
- M10 – Clamp on some machines
- M11 – Unclamp on some machines
- M13 – Spindle clockwise with coolant on some controls
- M14 – Spindle counterclockwise with coolant on some controls
- M19 – Spindle orientation
- M29 – Rigid tapping related function on certain controllers
- M41 – Low gear on machines supporting spindle gear control
- M42 – High gear on machines supporting spindle gear control
- M48 – Enable certain overrides on compatible controls
- M49 – Disable certain overrides on compatible controls
- M60 – Pallet-related function on some machining centers
- M98 – Call a subprogram on many FANUC-style controls
- M99 – Return from a subprogram or provide looping behavior on many compatible controls
The higher or less common the M-code number, the more important it becomes to verify its meaning in the machine documentation. Machine builders frequently assign M-codes to custom accessories and automation functions.
Which CNC M-Codes Are Used Most Often?
Although a CNC machine may support dozens of M-codes, machinists repeatedly encounter a relatively small group during normal milling and turning operations.
Six especially common commands are:
- M03 – Start spindle clockwise
- M05 – Stop spindle
- M06 – Change tool
- M08 – Turn flood coolant on
- M09 – Turn coolant off
- M30 – End and reset the program
A typical CNC milling process may therefore follow a sequence such as selecting a cutting tool, performing an M06 tool change, setting spindle speed, starting the spindle with M03, turning coolant on with M08, machining the part with G-code commands, switching coolant off with M09, stopping the spindle with M05, and finally ending the program with M30.
This demonstrates why M-codes are an essential part of CNC automation even though they do not usually define the cutting path itself.
How Do M-Codes Work in a CNC Program?
A CNC controller reads a machining program in blocks. Each block can contain commands defining positions, feeds, speeds, machine functions, or other instructions.
Some M-codes establish a condition that remains active until another command changes it. For example, after M03 starts the spindle, the spindle normally continues running until an M05 command stops it. Similarly, after M08 activates coolant, coolant normally remains on until M09 is executed.
Other M-codes perform a particular action once. M06 is a typical example because it initiates a tool-change operation rather than simply establishing a continuous condition.
This means that CNC programming depends not only on choosing the correct M-code but also on placing it correctly in the machining sequence.
For example, starting a cutting move before the spindle reaches the required operating condition can damage the cutter or workpiece. Forgetting to activate coolant during a demanding cutting operation may increase heat and tool wear.
CNC M-Code Program Example
The following simplified CNC milling program demonstrates how common M-codes can work together with G-code:
T01 M06
S2500 M03
G00 X0 Y0
G43 H01 Z10
M08
G01 Z-2.0 F150
G01 X50.0
G00 Z10.0
M09
M05
M30
The basic sequence can be interpreted as follows:
- T01 M06 selects tool 1 and performs the tool change.
- S2500 M03 sets the spindle speed to 2500 RPM and starts clockwise rotation.
- G00 rapidly positions the machine.
- G43 H01 applies the relevant tool length compensation on compatible controls.
- M08 turns flood coolant on.
- G01 commands controlled cutting movements.
- M09 turns coolant off.
- M05 stops the spindle.
- M30 ends the program.
This example is intended to explain CNC program structure rather than serve as a production-ready program. Actual syntax, safety moves, work offsets, compensation methods, and machine requirements must be checked for the specific CNC controller.
What Is the Difference Between G-Code and M-Code?
G-code and M-code perform different but complementary roles in CNC programming.
What Does G-Code Control?
G-code primarily controls the motion and machining behavior of the cutting tool. Common examples include:
- G00 – Rapid positioning
- G01 – Linear interpolation
- G02 – Clockwise circular interpolation
- G03 – Counterclockwise circular interpolation
Other G-codes can control coordinate systems, compensation modes, canned cycles, machining planes, and additional motion-related functions.
What Does M-Code Control?
M-codes usually control supporting machine functions such as:
- Starting or stopping the spindle
- Turning coolant on or off
- Changing tools
- Stopping the CNC program
- Controlling pallets or clamps
- Calling or returning from subprograms on compatible controls
G-code and M-code therefore do not replace each other. A CNC machining program normally requires both. The G-code defines the tool path, while the M-code creates the machine conditions required to execute that path.
Why Do M-Codes Differ Between CNC Machines?
One of the most important things to understand about CNC M codes is that they are not completely universal.
Controls from FANUC, Haas, Siemens, Mitsubishi, and other manufacturers can share many familiar commands, but machine builders can also define their own M-code functions. Additional differences can result from the accessories installed on a machine.
For example, a machining center equipped with a pallet changer, hydraulic fixture, probing system, automatic door, chip conveyor, or special coolant system may require M-codes that do not exist on a simpler CNC mill.
A custom M-code could be assigned to:
- Open or close a fixture
- Move a pallet
- Activate a parts catcher
- Control an automatic door
- Start a chip conveyor
- Operate a probing accessory
- Control an additional spindle
For this reason, never assume that an unfamiliar M-code copied from one machine performs the same function on another.
Before transferring a CNC program between machines, check the CNC controller manual, machine-builder documentation, machine-specific M-code list, and configuration of installed auxiliary equipment.
How Are M-Codes Used for Spindle Control?
Spindle control is one of the most important applications of M-code in CNC machining.
M03 normally starts clockwise spindle rotation, M04 starts counterclockwise rotation, and M05 stops the spindle.
However, these commands should not be confused with spindle speed.
S3000 M03
Here, S3000 requests a spindle speed of 3000 RPM, while M03 commands the spindle to rotate clockwise.
This distinction becomes important when optimizing machining parameters. Changing from 1500 RPM to 3000 RPM normally changes the S value, not the meaning of M03.
How Are M-Codes Used for Coolant Control?
Coolant is often controlled through M07, M08, and M09.
M08 is commonly used for flood coolant. During machining, coolant can help remove heat from the cutting zone, improve chip evacuation, reduce built-up material on the cutting edge, and support more consistent tool life.
M07 commonly refers to mist coolant where that function is available, while M09 usually switches coolant off.
Modern CNC machining centers may also use high-pressure coolant, through-spindle coolant, air blast systems, or specialized coolant delivery. These features can require machine-specific M-codes, so operators should not assume that the general coolant commands cover every system.
How Are M-Codes Used for CNC Tool Changes?
Automatic tool changing is especially important in CNC milling because a single component may require several cutting tools.
A program may contain:
T03 M06
On many machining centers, T03 identifies tool number 3 and M06 commands the automatic tool changer to install the selected tool.
The distinction between T-code and M-code is important. The T command identifies the desired tool, while M06 initiates the actual machine function required to change it.
A single machined component may use separate tools for:
- Fresatura di superfici piane
- Rough pocket milling
- Finish contouring
- Foratura
- Maschiatura
- Smussatura
Automatic tool changing allows these operations to run sequentially with much less manual intervention.
How Do M-Codes Affect Real CNC Machining?
M-code sequencing can directly affect machining efficiency, cutting conditions, and process reliability.
Face Milling
A typical face-milling process may start the spindle with M03 and activate coolant with M08 before the tool contacts the workpiece. G-code then controls the cutting passes. After machining, M09 turns coolant off and M05 stops spindle rotation.
An incorrect sequence can cause the tool to enter the material before the spindle is operating correctly or result in machining without the intended coolant condition.
Maschiatura
Tapping requires careful synchronization between spindle rotation and feed movement. Some controllers use M29 as part of rigid tapping operation setup, but this is not a universal function across every controller.
The actual tapping procedure should always follow the machine manufacturer’s programming requirements.
Multi-Tool CNC Machining
Complex precision components often require roughing, drilling, finishing, threading, and chamfering in a single setup. Tool-change commands allow the machining center to move between these operations automatically.
At Tuofa CNC Germany, this type of automated machining sequence is particularly useful for custom precision components where several geometric features must be produced while maintaining consistent relationships between surfaces, holes, threads, pockets, and edges.
Do M-Codes Change for Different Materials?
The fundamental meaning of common M-codes normally does not change simply because a different workpiece material is being machined.
For example, M03 still commands the appropriate clockwise spindle function whether the workpiece is aluminum, stainless steel, brass, titanium, or engineering plastic.
What changes are the machining parameters and process strategy.
Different materials may require adjustments to:
- Spindle speed
- Velocità di avanzamento
- Cutting tool geometry
- Tool material or coating
- Depth of cut
- Coolant strategy
- Evacuazione dei trucioli
For example, a programmer may change the S value and F value when moving from aluminum machining to stainless steel machining. The program may also use a different coolant strategy, but M03 itself does not become a different command simply because the material has changed.
Are M-Codes Used Outside CNC Milling?
M-codes are used across many forms of CNC equipment, not just three-axis CNC mills.
They can be found in:
- CNC milling machines
- CNC lathes
- Turning centers
- Multi-axis machining centers
- CNC plasma cutting systems
- Automated manufacturing cells
On CNC lathes, M-codes may control spindle direction, coolant, chuck-related functions, tailstocks, parts catchers, or additional machine equipment.
On plasma cutting equipment, M-code-type commands may control torch, gas, arc-related functions, or auxiliary equipment. However, plasma systems can have highly controller-specific programming, so a general milling M-code list should not be applied directly without verification.
Common M-Code Programming Mistakes
Many CNC programming problems are caused not by complex tool-path calculations but by incorrect assumptions about machine functions.
Using the Wrong Controller’s M-Code List
A program written for one CNC control should not automatically be transferred to another machine without checking machine-specific commands.
Assuming Every M-Code Is Universal
Basic commands such as M03, M05, M08, and M09 are widely recognized, but many other M-codes are machine specific.
Confusing M03 With Spindle Speed
M03 normally controls spindle direction and startup. The spindle speed is typically specified with the S command.
Forgetting to Turn Coolant Off
If M09 is omitted, coolant may remain active longer than intended, depending on the program and machine behavior.
Incorrect Spindle and Tool-Change Sequencing
Certain machines require particular spindle, positioning, or safety conditions before performing a tool change. The correct procedure depends on machine configuration.
Running an Unverified M-Code
Unknown commands should never be tested casually on production equipment. An unfamiliar M-code may control a clamp, chuck, pallet, door, spindle, or another physical function.
Benefits of Using M-Codes in CNC Programming
M-codes make it possible to integrate machine functions directly into the CNC program rather than relying on the operator to perform each action manually.
Important benefits include:
- Greater machine automation
- Less manual intervention
- Repeatable machining sequences
- Automatic spindle control
- Automatic coolant control
- Automatic tool changes
- More efficient multi-operation machining
- Consistent machine-state control
- Better integration with fixtures and automation systems
In production CNC machining, this automation helps a correctly programmed machine repeat the same sequence from part to part while reducing unnecessary operator actions.
CNC M-Code Quick Reference
| M-Code | Common Function |
|---|---|
| M00 | Program stop |
| M01 | Optional program stop |
| M03 | Spindle clockwise |
| M04 | Spindle counterclockwise |
| M05 | Spindle stop |
| M06 | Tool change |
| M07 | Mist coolant on where supported |
| M08 | Flood coolant on |
| M09 | Coolant off |
| M19 | Spindle orientation on compatible controls |
| M29 | Rigid tapping related function on certain controls |
| M30 | End program and reset/rewind on many controls |
| M98 | Call subprogram on many FANUC-style controls |
| M99 | Return from subprogram or looping function on compatible controls |
Important: This CNC M code list is intended as a general reference. Always verify M-code functions against the manual for the specific CNC controller and machine tool.
Frequently Asked Questions About CNC M-Codes
What does M stand for in CNC programming?
M is commonly associated with miscellaneous or machine functions. M-codes generally control auxiliary CNC machine operations such as the spindle, coolant, tool changer, and program control.
What does M03 mean in CNC?
M03 commonly starts the CNC spindle in the clockwise direction. The required spindle speed is normally defined separately with an S command.
What does M05 mean in CNC?
M05 normally stops spindle rotation. It is commonly used before tool changes and at the end of machining operations.
What is M06 in CNC?
M06 commonly commands an automatic tool change on CNC machining centers. It is typically used together with a T command identifying the required tool.
What is M08 in CNC?
M08 normally activates flood coolant on machines equipped with this coolant system.
What is the difference between M03 and M04?
M03 generally commands clockwise spindle rotation, while M04 commands counterclockwise spindle rotation.
What is the difference between M02 and M30?
Both can be used to terminate a CNC program on compatible controls, but M30 typically includes additional reset or rewind behavior. Exact behavior depends on the controller.
Are CNC M-codes universal?
No. Many common M-codes are shared across different controls, but machine manufacturers and controller developers can assign different functions to certain M-code numbers.
Can multiple M-codes be used in one CNC program?
Yes. A CNC machining program normally contains many M-codes controlling different stages of the process. Whether multiple M-codes can be placed in the same block depends on controller rules.
Are Haas and FANUC M-codes exactly the same?
No. Haas and FANUC-style systems share a number of familiar commands, but their complete M-code sets and machine-specific functions should not be assumed to be identical.
Conclusione
CNC M-codes are an essential part of machine programming because they control many of the supporting functions required for automated machining. Commands such as M03, M05, M06, M08, M09, and M30 are frequently used to manage spindle operation, tool changes, coolant, and program completion.
While G-code primarily controls tool movement, M-code controls the machine functions that allow those tool paths to be executed correctly. Together, they form the foundation of practical CNC programming.
The most important rule when working with CNC M codes is not to assume every code is universal. Common commands may behave similarly across many machines, while other M-codes can be specific to a controller, machine builder, or installed accessory.
For production parts requiring CNC milling, CNC turning, multi-tool machining, tight tolerances, complex features, or customized machining strategies, Tuofa CNC Germania combines CNC programming with practical manufacturing experience to support reliable custom precision machining from prototypes to production components.