Free shipping above ₹10,000  ·  GST invoice on every order +91 99111 93212  ·  Mon–Sat, 9:30 to 18:30 IST

G-code quick reference

The G and M codes a CNC controller interprets, what each one does, and which are modal — with the ones that differ between controllers marked.

How to read this

A modal code stays in effect until something replaces it. G1 is modal: once set, every following line cuts at feed rate until a G0 or G2/G3 takes over. A non-modal code applies to its own line and no further.

Codes marked (varies) are not consistent between controllers. Check the manual for the machine in front of you before relying on one.

Motion

CodeDoesModal
G0Rapid move to a position. Not a cutting move — the path between two points is not guaranteed straight on every controller.yes
G1Linear move at the current feed rate.yes
G2Clockwise arc. Centre given by I/J/K, or radius by R.yes
G3Counter-clockwise arc. Same arguments as G2.yes
G4Dwell. P in seconds, or milliseconds (varies).no

Coordinates and units

CodeDoesModal
G17Select the XY plane for arcs. G18 is XZ, G19 is YZ.yes
G20Inches.yes
G21Millimetres.yes
G28Return to machine home. Arguments vary considerably (varies).no
G53Move in machine coordinates for this line only, ignoring any work offset.no
G54Work coordinate system 1. G55 to G59 select the others.yes
G90Absolute positioning — coordinates are measured from the work origin.yes
G91Incremental positioning — coordinates are measured from where the tool is now.yes
G92Set the current position to the given coordinates without moving. Offsets it writes survive a reset on some controllers (varies).yes

Feed and tooling

CodeDoesModal
G93Inverse time feed mode.yes
G94Feed per minute — the usual mode.yes
G95Feed per revolution. Lathes mostly.yes
FFeed rate, in current units per minute.yes
SSpindle speed, in rev/min.yes
TSelect tool. On most controllers this only selects; M6 performs the change.yes

Compensation

CodeDoesModal
G40Cancel cutter radius compensation.yes
G41Cutter compensation, tool left of the path.yes
G42Cutter compensation, tool right of the path.yes
G43Apply tool length offset, H selects which.yes
G49Cancel tool length offset.yes

M codes

CodeDoes
M0Programmed stop. Waits for the operator.
M1Optional stop — honoured only when the operator has enabled it.
M2End of program.
M3Spindle on, clockwise.
M4Spindle on, counter-clockwise.
M5Spindle stop.
M6Tool change.
M7Mist coolant on (varies — some controllers swap M7 and M8).
M8Flood coolant on (varies).
M9Coolant off.
M30End of program and rewind to the start.

Things that catch people out

  • G0 is not a straight line. Many controllers move each axis at its own maximum rate, so the tool takes a dog-leg. Never rapid past a fixture assuming a straight path.
  • G91 left set is behind a good share of crashes. An incremental move after a program expected absolute goes somewhere nobody intended.
  • Arc R versus I/J. With R, an arc of more than 180 degrees is ambiguous and controllers resolve it differently. I/J/K are unambiguous — prefer them.
  • G92 is not a work offset. It shifts the coordinate system on top of whatever G54 already did, and forgetting it is set produces an error that looks like a broken machine.
  • Tool change is two steps. T selects, M6 changes. T2 alone changes nothing on most controllers.

Something wrong or missing here? Tell us — this page is maintained by hand and corrections from the shop floor are the useful kind.