CNC G-Code Cheat Sheet

The G-codes and M-codes you'll actually run into most often, for a quick look-up at the control.

Motion (G-codes)

CodeFunction
G0Rapid positioning move, no cutting.
G1Linear feed move, cutting at the programmed feed rate.
G2 / G3Circular interpolation, clockwise / counterclockwise.
G28Return to machine home / reference position.

Compensation & Offsets

CodeFunction
G40Cancel cutter diameter compensation.
G41 / G42Cutter compensation left / right of the programmed path.
G43Tool length compensation, positive direction.
G54–G59Work coordinate system offsets (1st through 6th).

Units & Modes

CodeFunction
G20 / G21Inch mode / metric (mm) mode.
G90 / G91Absolute positioning / incremental positioning.
G94 / G95Feed per minute / feed per revolution.

Canned Cycles

CodeFunction
G80Cancel any active canned cycle.
G81Basic drilling cycle.
G82Drilling with a dwell at the bottom (spot facing / countersinking).
G83Peck drilling cycle, full retract between pecks.
G84Rigid tapping cycle.

Machine Functions (M-codes)

CodeFunction
M0 / M1Program stop / optional stop.
M3 / M4 / M5Spindle on clockwise / counterclockwise / spindle stop.
M6Tool change.
M8 / M9Coolant on / coolant off.
M30Program end and reset to the beginning.

Codes vary between controls

This chart reflects widely used Fanuc-style conventions, which most controls (Haas, Fanuc, and many others) follow closely — but Siemens, Heidenhain, and some older or proprietary controls use different codes for the same functions, and even Fanuc-style controls vary slightly in canned cycle parameters. Always check your specific control's programming manual before running unfamiliar code on a machine.

Modal vs. non-modal codes

Most G-codes are modal — once called, they stay in effect for every following block until a different code in the same group cancels or replaces them, which is why a program doesn't need to repeat G1 on every single line. M-codes and a handful of G-codes (like G28) are non-modal one-shot commands instead.

This is a memory jog, not a programming reference

Canned cycles in particular (G81–G89) take several parameters beyond what's listed here — retract plane, dwell time, peck increment, and more — that vary by control and cycle. Use this chart to recall what a code generally does, then check the actual parameter list before programming a cycle from scratch.