M-code reference

M02: End of program

M02 is end of program. Ends the program. On many controls it does not rewind to the start. It is non-modal, so it acts only on the line it is written on.

What M02 does

M02 ends the program and resets the machine. On older controls it does not rewind, which is why M30 replaced it in most programs. On many modern controls the two behave the same.

TypeM-code
MachineMill and lathe
GroupProgram control
ModalNo: acts only on its own line

M02 example

M02

Program ends.

WordWhat it means here
M02End of program

Codes people confuse with M02

CodeWhat it does instead
M30 End of program and rewind. Ends the program and returns to the first line, ready for the next part.
M00 Program stop. Stops the program until the operator presses cycle start.

Other codes in the program control group

These also act only on their own line.

  • M00 Program stop
  • M01 Optional stop
  • M30 End of program and rewind
  • M97 Local subprogram call (Haas)
  • M98 Subprogram call
  • M99 Subprogram end / return

Meanings follow the common Fanuc-style standard that Haas, Okuma (EIA mode), Mitsubishi, LinuxCNC and most other controls share for this code. Options and parameters change details from machine to machine, so check the manual for your control.

Quick check: M02

  1. What does M02 do? (Mill and lathe)

  2. Which code: Ends the program. On many controls it does not rewind to the start.(Mill and lathe)

  3. What does M30 do? (Mill and lathe)

Show the answers
  1. Ends the program. On many controls it does not rewind to the start.
  2. M02
  3. Ends the program and returns to the first line, ready for the next part.

Drill this code with the rest of the core set

More practice hubs

Frequently asked questions

What does M02 mean in CNC programming?
End of program. Ends the program. On many controls it does not rewind to the start.
Is M02 modal?
No. M02 acts only on the line where it is written; the next line goes back to whatever modal codes were already active.
What is the difference between M02 and M30?
M02 (end of program): ends the program. On many controls it does not rewind to the start. M30 (end of program and rewind): ends the program and returns to the first line, ready for the next part.
What is the difference between M02 and M00?
M02 (end of program): ends the program. On many controls it does not rewind to the start. M00 (program stop): stops the program until the operator presses cycle start.

G-Code Sprint is an educational practice tool only. It is not a CNC simulator, machine controller, safety manual, or replacement for instruction. Always follow your instructor, employer, machine manual, and shop procedures.

Free preview · no card Try G-Code Sprint