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.

M-Codes vs. G-Codes

G-codes control where the machine moves — lines, arcs, and coordinate systems. M-codes control everything else happening around that motion — spindle, coolant, and program flow. A single line of code often carries both, like G01 X1.0 M08, which feeds to X1.0 while turning on coolant.

Order matters. Most controllers execute the M-code either before or after the motion on the same block, depending on the controller and the specific code — a tool change (M06) typically completes before the next motion starts, while coolant-on (M08) is usually safe to combine with the first cut. When timing is critical, put the M-code on its own line to force the sequence you want rather than relying on the control’s default order.

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.