M-codes (miscellaneous or machine codes) control machine functions rather than motion: the spindle, coolant, tool changer, and program flow. Exact codes vary by machine, but a common core is nearly universal.
| Code | Function |
|---|---|
| M00 | Program stop (resume with cycle start) |
| M01 | Optional stop (only if the switch is on) |
| M02 | Program end |
| M03 / M04 | Spindle on clockwise / counterclockwise |
| M05 | Spindle stop |
| M06 | Tool change |
| M08 / M09 | Coolant on / off |
| M19 | Spindle orient |
| M30 | Program end and rewind |
| M98 / M99 | Call / return from subprogram |
Always confirm M-codes against your specific controller manual — assignments above M30 differ between builders.
FAQ
Are M-codes standardized across all machine controls? Not entirely. Common M-codes like M03, M05, M08, and M30 are widely consistent, but many controls also support manufacturer-specific M-codes for things like pallet changers or custom macros, so check your specific control’s documentation for anything beyond the basics.
What does M30 do? M30 ends the program and typically rewinds it back to the beginning, resetting the program pointer so the next cycle start reruns from the top, unlike M02 which simply ends the program without necessarily rewinding.
Related: the G-Code Cheat Sheet and Machining Glossary.
