CNC (Computer Numerical Control) technology is essential in the modern manufacturing industry. Machines rely on instructions provided through a CNC program controller, with G and M codes playing a vital role in their operation.
Within programs like AutoCAD and CAM, M-codes complement G-codes by managing workpiece positioning and guiding the machine during operations. Tasks such as tool changes and coolant usage are dictated by M-codes.
Every machine has specific M-codes tailored for its operations. Operators must be familiar with these codes for activities like changing tools, controlling spindles, and managing coolants, following the manufacturer’s guidelines.
In CNC machines, M-code functions are used to control various auxiliary functions such as turning on and off coolant systems, spindle rotation, tool changes, and more.
Some common M-codes include:
– M03: Spindle clockwise rotation
– M04: Spindle counterclockwise rotation
– M05: Stop spindle rotation
– M06: Tool change
– M08: Turn on coolant
– M09: Turn off coolant
These M-codes are essential for automating the machining process and ensuring that the machine operates efficiently and safely. By incorporating M-code functions into CNC programs, operators can streamline production and achieve precise results.
Fanuc Controllers and M-codes
The Fanuc controllers employ a variety of M-codes to command CNC machines. Each M-code is responsible for controlling specific functions as defined by the machine manufacturer.
M-codes direct machine actions such as stopping the program, starting the spindle, and changing tools. Understanding the functionality of M-codes is crucial for efficient machine operation.
Lathe M-codes

| M code | Description |
|---|---|
| M00 | Program stop |
| M01 | Optional program stop |
| M02 | End of program |
| M03 | Spindle start forward CW |
| M04 | Spindle start reverse CCW |
| M05 | Spindle stop |
| M08 | Coolant on |
| M09 | Coolant off |
| M29 | Rigid tap mode |
| M30 | End of program reset |
| M40 | Spindle gear at middle |
| M41 | Low Gear Select |
| M42 | High Gear Select |
| M68 | Hydraulic chuck close |
| M69 | Hydraulic chuck open |
| M78 | Tailstock advancing |
| M79 | Tailstock reversing |
| M94 | Mirrorimage cancel |
| M95 | Mirrorimage of X axis |
| M98 | Subprogram call |
| M99 | End of subprogram |
Milling M-codes

| M code | Description |
|---|---|
| M00 | Program stop |
| M01 | Optional program stop |
| M02 | End of program |
| M03 | Spindle start forward CW |
| M04 | Spindle start reverse CCW |
| M05 | Spindle stop |
| M06 | Tool change |
| M07 | Coolant ON – Mist coolant/Coolant thru spindle |
| M08 | Coolant ON – Flood coolant |
| M09 | Coolant OFF |
| M19 | Spindle orientation |
| M28 | Return to origin |
| M29 | Rigid tap |
| M30 | End of program (Reset) |
| M41 | Low gear select |
| M42 | High gear select |
| M94 | Cancel mirrorimage |
| M95 | Mirrorimage of X axis |
| M96 | Mirrorimage of Y axis |
| M98 | Subprogram call |
| M99 | End of subprogram |
Understanding G and M codes is crucial for effective CNC machine operation. G-codes determine tasks, while M-codes manage operations and movements.
CNC machining relies on CAD/CAM software to program parts, enhancing engineers’ comprehension of machine instructions.
