M-Code Reference

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.

Scroll to Top

The calculators and tools on Formula Factory are provided for general guidance and informational purposes only. Results are estimates based on standard formulas and the values you enter — they do not constitute professional engineering, electrical, or architectural advice. Always verify calculations with a qualified professional before making decisions for any safety-critical, code-compliance, or commercial application. Formula Factory makes no representations or warranties as to the accuracy or completeness of any result, and accepts no liability for errors, omissions, or any outcomes arising from reliance on this information.