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
Code
Does
Modal
G0
Rapid move to a position. Not a cutting move — the path between two points is not guaranteed straight on every controller.
yes
G1
Linear move at the current feed rate.
yes
G2
Clockwise arc. Centre given by I/J/K, or radius by R.
yes
G3
Counter-clockwise arc. Same arguments as G2.
yes
G4
Dwell. P in seconds, or milliseconds (varies).
no
Coordinates and units
Code
Does
Modal
G17
Select the XY plane for arcs. G18 is XZ, G19 is YZ.
yes
G20
Inches.
yes
G21
Millimetres.
yes
G28
Return to machine home. Arguments vary considerably (varies).
no
G53
Move in machine coordinates for this line only, ignoring any work offset.
no
G54
Work coordinate system 1. G55 to G59 select the others.
yes
G90
Absolute positioning — coordinates are measured from the work origin.
yes
G91
Incremental positioning — coordinates are measured from where the tool is now.
yes
G92
Set the current position to the given coordinates without moving. Offsets it writes survive a reset on some controllers (varies).
yes
Feed and tooling
Code
Does
Modal
G93
Inverse time feed mode.
yes
G94
Feed per minute — the usual mode.
yes
G95
Feed per revolution. Lathes mostly.
yes
F
Feed rate, in current units per minute.
yes
S
Spindle speed, in rev/min.
yes
T
Select tool. On most controllers this only selects; M6 performs the change.
yes
Compensation
Code
Does
Modal
G40
Cancel cutter radius compensation.
yes
G41
Cutter compensation, tool left of the path.
yes
G42
Cutter compensation, tool right of the path.
yes
G43
Apply tool length offset, H selects which.
yes
G49
Cancel tool length offset.
yes
M codes
Code
Does
M0
Programmed stop. Waits for the operator.
M1
Optional stop — honoured only when the operator has enabled it.
M2
End of program.
M3
Spindle on, clockwise.
M4
Spindle on, counter-clockwise.
M5
Spindle stop.
M6
Tool change.
M7
Mist coolant on (varies — some controllers swap M7 and M8).
M8
Flood coolant on (varies).
M9
Coolant off.
M30
End 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.