CNC PROGRAMMING
CNC G and M Codes
A practical overview of common preparatory and auxiliary codes, with safety notes for functions that vary by control and machine builder.

G codes: motion and machining commands
- G00 — rapid positioning
- G01 — linear feed move
- G02 / G03 — clockwise / counterclockwise circular move
- G17 / G18 / G19 — select XY / XZ / YZ plane
- G20 / G21 — inch / millimetre units
- G40 / G41 / G42 — cancel / enable left / right cutter compensation
- G54–G59 — select a work coordinate system
- G81 — a common drilling cycle; parameters depend on the control
- G90 / G91 — absolute / incremental programming
M codes: machine auxiliary functions
- M00 — mandatory program stop
- M01 — optional stop; the panel option must be enabled
- M03 / M04 / M05 — spindle clockwise / counterclockwise / stop
- M06 — tool change; implementation depends on machine configuration
- M08 / M09 — coolant on / off
- M30 — program end and rewind on many controls
- M98 / M99 — call a subprogram / return from it
Before running a program
The same code can behave differently depending on control, machine builder, parameters and active modal state. M codes are often assigned by the machine builder. Canned-cycle syntax such as G81 also varies by control family. Check the machine programming manual and postprocessor output. Verify simulation, tool offsets, work zero and safe motions before running code on a real machine.
Use this list as a general reference; the machine manual and a verified postprocessor take precedence.

