CNC mill · M-code
M30: program end and reset
M30 ends the program, stops the spindle and coolant, and rewinds to the start ready for the next part. Formats below from Haas and LinuxCNC, each from its maker.
Searching "M30" alone mostly finds the M30 metric screw size: that is a 30 mm thread, not this code.
Worked example
A safe program end. Written for this page in the Haas format.
G00 Z1. M09G91 G28 Z0G90M30How each control writes it
Haas M30
One source: Haas Automation, the control's maker
- Stops the spindle and coolant (including through-spindle coolant) and returns the cursor to the program start.
Source: Haas Automation, mill M30
LinuxCNC M30 (or M2)
One source: the LinuxCNC project, the control's maker
- M30 also exchanges pallet shuttles; both reset G54, G17, G90, G94, G40, M5, M9 and G1.
- Lines after M2/M30 do not run.
Source: LinuxCNC documentation, "M2, M30 Program End" (archived Oct 24, 2026)
No Fanuc row yet: that chapter of the 0i manual has not been read.
Haas follows Fanuc's numbering, but options and parameters differ between controls: check your control's manual.