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)
| Code | Function |
|---|---|
| G0 | Rapid positioning move, no cutting. |
| G1 | Linear feed move, cutting at the programmed feed rate. |
| G2 / G3 | Circular interpolation, clockwise / counterclockwise. |
| G28 | Return to machine home / reference position. |
Compensation & Offsets
| Code | Function |
|---|---|
| G40 | Cancel cutter diameter compensation. |
| G41 / G42 | Cutter compensation left / right of the programmed path. |
| G43 | Tool length compensation, positive direction. |
| G54–G59 | Work coordinate system offsets (1st through 6th). |
Units & Modes
| Code | Function |
|---|---|
| G20 / G21 | Inch mode / metric (mm) mode. |
| G90 / G91 | Absolute positioning / incremental positioning. |
| G94 / G95 | Feed per minute / feed per revolution. |
Canned Cycles
| Code | Function |
|---|---|
| G80 | Cancel any active canned cycle. |
| G81 | Basic drilling cycle. |
| G82 | Drilling with a dwell at the bottom (spot facing / countersinking). |
| G83 | Peck drilling cycle, full retract between pecks. |
| G84 | Rigid tapping cycle. |
Machine Functions (M-codes)
| Code | Function |
|---|---|
| M0 / M1 | Program stop / optional stop. |
| M3 / M4 / M5 | Spindle on clockwise / counterclockwise / spindle stop. |
| M6 | Tool change. |
| M8 / M9 | Coolant on / coolant off. |
| M30 | Program 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.
Find It on Amazon
Search Amazon directly for tooling, gauges, and shop supplies.