Knowledge / Reference
G-Codes & M-Codes
Common CNC preparatory (G) and miscellaneous (M) codes for machining centers and lathes. The codes follow the widely used Fanuc-style convention; your machine's programming manual is the final word.
CNC Programming Reference
96 codes
G-Codes: Machining Centers
Preparatory codes that set the type of move, plane, units, offsets and canned cycles. Most are modal: they stay active until another code from the same group replaces them.
| G-Code | Function |
|---|---|
| G00 | Rapid positioning (non-cutting move at maximum traverse rate) |
| G01 | Linear interpolation (straight-line move at the programmed feed rate) |
| G02 | Circular interpolation, clockwise |
| G03 | Circular interpolation, counterclockwise |
| G04 | Dwell (pause for a programmed time) |
| G09 | Exact stop check, current block only |
| G10 | Programmable data input (set work and tool offsets from the program) |
| G15 | Polar coordinate command cancel |
| G16 | Polar coordinate command |
| G17 | XY plane selection |
| G18 | ZX plane selection |
| G19 | YZ plane selection |
| G20 | Inch input |
| G21 | Metric (millimeter) input |
| G28 | Return to machine reference point (home), through an intermediate point |
| G29 | Return from reference point |
| G30 | Return to 2nd, 3rd or 4th reference point |
| G31 | Skip function (used for probing) |
| G40 | Cutter radius compensation cancel |
| G41 | Cutter radius compensation, left of the path |
| G42 | Cutter radius compensation, right of the path |
| G43 | Tool length compensation, positive direction |
| G44 | Tool length compensation, negative direction |
| G49 | Tool length compensation cancel |
| G50 | Scaling cancel |
| G51 | Scaling |
| G50.1 | Programmable mirror image cancel |
| G51.1 | Programmable mirror image |
| G52 | Local coordinate system setting |
| G53 | Machine coordinate system selection (current block only) |
| G54 | Work coordinate system 1 |
| G55 | Work coordinate system 2 |
| G56 | Work coordinate system 3 |
| G57 | Work coordinate system 4 |
| G58 | Work coordinate system 5 |
| G59 | Work coordinate system 6 |
| G54.1 | Additional work coordinate systems (selected with P1, P2, ...) |
| G61 | Exact stop mode |
| G64 | Cutting mode (continuous path, no exact stop between blocks) |
| G65 | Macro call, current block only |
| G66 | Modal macro call |
| G67 | Modal macro call cancel |
| G68 | Coordinate system rotation |
| G69 | Coordinate system rotation cancel |
| G73 | High-speed peck drilling cycle (chip breaking) |
| G74 | Left-hand (counter) tapping cycle |
| G76 | Fine boring cycle (spindle orients and shifts off the wall before retract) |
| G80 | Canned cycle cancel |
| G81 | Drilling cycle (spot drilling) |
| G82 | Drilling cycle with dwell at the bottom (counterboring, spot facing) |
| G83 | Peck drilling cycle (full retract, for deep holes) |
| G84 | Right-hand tapping cycle |
| G85 | Boring cycle (feed in, feed out) |
| G86 | Boring cycle (spindle stops at the bottom, rapid out) |
| G87 | Back boring cycle |
| G88 | Boring cycle (dwell and spindle stop at the bottom, manual retract) |
| G89 | Boring cycle with dwell at the bottom, feed out |
| G90 | Absolute programming |
| G91 | Incremental programming |
| G92 | Coordinate system setting (workpiece shift) |
| G94 | Feed per minute |
| G95 | Feed per revolution |
| G98 | Canned cycle return to the initial point |
| G99 | Canned cycle return to the R point |
G-Codes: Lathes
Fanuc lathes (G-code system A) share most of the milling codes for moves, units and work offsets, but use the codes below differently. Lathes program X as a diameter.
| G-Code | Function |
|---|---|
| G32 | Thread cutting (single pass, constant lead) |
| G50 | Maximum spindle speed clamp; also coordinate system setting on older controls |
| G70 | Finishing cycle (runs the profile defined for G71, G72 or G73) |
| G71 | Stock removal cycle, turning (roughing along Z) |
| G72 | Stock removal cycle, facing (roughing along X) |
| G73 | Pattern repeating cycle (for castings and forgings) |
| G74 | Peck drilling along Z, or face grooving |
| G75 | Grooving cycle along X (OD or ID grooving, parting) |
| G76 | Multiple-pass threading cycle |
| G90 | Outer and inner diameter cutting cycle (single pass) |
| G92 | Thread cutting cycle (single pass) |
| G94 | End face cutting cycle (single pass) |
| G96 | Constant surface speed (spindle speed changes with diameter) |
| G97 | Constant spindle speed (constant surface speed cancel) |
| G98 | Feed per minute |
| G99 | Feed per revolution |
M-Codes
Miscellaneous codes that switch machine functions such as the spindle, coolant and tool changer, and control program flow. Above M30, many codes are defined by the machine builder.
| M-Code | Function |
|---|---|
| M00 | Program stop (operator presses Cycle Start to continue) |
| M01 | Optional stop (stops only when Optional Stop is switched on) |
| M02 | End of program |
| M03 | Spindle on, clockwise |
| M04 | Spindle on, counterclockwise |
| M05 | Spindle stop |
| M06 | Tool change |
| M07 | Mist coolant on |
| M08 | Flood coolant on |
| M09 | Coolant off |
| M19 | Spindle orientation |
| M29 | Rigid tapping mode (Fanuc) |
| M30 | End of program, rewind and reset |
| M97 | Local subprogram call (Haas) |
| M98 | Subprogram call |
| M99 | Subprogram end and return; at the end of a main program, repeats it |
No matching codes. Try a different search or clear the search field.
G- and M-codes vary between controls (Fanuc, Haas, Siemens, Heidenhain, Mazak and others) and between machine builders. Check the programming manual for your machine before running a program.