ThingConnect

CNC programs & data

M-codes

M-codes are the miscellaneous commands in a CNC program that switch machine functions — spindle, coolant, tool change, program stop and program end — as opposed to G-codes, which drive motion.

Updated November 20263 min read

← All glossary terms

G-codes move the axes; M-codes switch everything else on and off. They also mark the moments that matter for monitoring — when a program pauses, when it ends, and when a part is done.

Common M-codes

  • M00

    Function
    Program stop — waits for cycle start
  • M01

    Function
    Optional stop — only if the optional-stop switch is on
  • M02

    Function
    End of program (no rewind on some controls)
  • M30

    Function
    End of program and rewind to the start
  • M03 / M04 / M05

    Function
    Spindle clockwise / counter-clockwise / stop
  • M06

    Function
    Tool change
  • M08 / M09

    Function
    Coolant on / off

These are the widely shared basics. Numbers above these are often assigned by the machine builder, so the same code can mean different things on two machines.

How M-codes affect running vs idle

A program sitting on M00 or M01 has stopped, but some controls still report it as “in automatic”. Builder-specific M-codes that wait for an outside signal — a pallet change, a door, a bar feeder — can look like running time too. ThingConnect lets you name such a waiting M-code per machine; while the control sits on it, the time is recorded as idle with that label, not as time in cycle.

M-codes and part counting

Many programs count a part at M30, either through the control’s own counter or by incrementing a macro variable just before it. ThingConnect measures cycle time from those part-count increases, so where the count happens in the program decides where one cycle ends and the next begins.

On the floor

On a two-pallet machine, pallet 1 finishes and the control keeps reporting “running” while it waits for pallet 2 to be ready. That wait shows up as a machine-builder M-code — M60 on the machines we’ve seen it on. Catching that M-code and marking the wait as idle stops it inflating the machine’s uptime.

Frequently asked questions

M99 ends a subprogram and returns to the program that called it. Used at the end of a main program, it loops straight back to the start without stopping, which keeps a machine cycling but means an end-of-program part counter never fires for those parts.

Usually only the machine builder or an integrator can, because a new M-code has to be wired into the machine’s own logic. Custom M-codes are common for pallet changers, probes, bar feeders and part catchers, so check the builder’s documentation before relying on one.

Related terms

Filed under

CNC programs & data

Live demo

See ThingConnect on a real shop floor

A one-on-one walkthrough with our team.

Book a demo
Talk to our team

Get running and idle time that understands your machines’ own M-codes