What is the difference between G-codes and M-codes?

G-codes control motion and modes. M-codes switch machine functions like spindle, coolant and tool change.

G-codes tell the machine how to move. M-codes tell it to switch something on or off. Both appear in the same program, often on the same line.

G-codes: geometry and modes

  • G00: rapid move to a position
  • G01: straight cut at a set feed rate
  • G02 and G03: clockwise and counter-clockwise arcs
  • G20 and G21: inch or metric units
  • G90 and G91: absolute or incremental positioning

Many G-codes are modal. Once set, they stay active until another code in the same group replaces them.

M-codes: machine functions

  • M03 and M05: spindle on clockwise, spindle stop
  • M06: tool change
  • M08 and M09: coolant on and off
  • M30: end of program and rewind

The catch

The common codes above are widely shared. Beyond them, meanings drift between controllers and machine builders. One control’s M-code for a pallet change may mean something else entirely on another. Always confirm in your machine’s documentation.

See the programming concepts category or read a full program.

All questions