CNC mill · M-code

M02: program end

M02 ends the program. M30 is the usual way to end one. Formats below from Haas and LinuxCNC, each from its maker.

Worked example

End the program. Written for this page in the Haas format.

G00 Z1. M09G91 G28 Z0G90M02 (M30 is the usual choice)

How each control writes it

Haas M02

One source: Haas Automation, the control's maker

  • M02 ends a program; the most common way is M30.

Source: Haas Automation, mill M02

LinuxCNC M2

One source: the LinuxCNC project, the control's maker

  • M2 and M30 both reset G54, G17, G90, G94, G40, M5, M9 and G1.
  • Lines after M2 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.