G-Code and M-Code List (CNC Reference)
The G and M codes found in most CNC programs, with their groups, meanings and notes.
G-code is the language of CNC machines. G codes (“preparatory” codes) set how the machine moves: G00 is a rapid move, G01 a straight cut at the feed rate, G02 and G03 clockwise and counterclockwise arcs. M codes (“miscellaneous” codes) switch things on and off: M03 starts the spindle, M08 turns on coolant, M30 ends the program.
The table lists the codes that appear in most mill and lathe programs, grouped by what they control. Most G codes are modal: once given, they stay in force until another code from the same group replaces them.
The table
| Code | Group | Meaning | Notes |
|---|---|---|---|
| G00 | Motion | Rapid positioning | Moves at the machine's rapid rate; not for cutting |
| G01 | Motion | Linear move at feed rate F | Straight-line cutting |
| G02 | Motion | Circular move, clockwise | Center by I, J, K or radius R |
| G03 | Motion | Circular move, counterclockwise | Center by I, J, K or radius R |
| G04 | Dwell | Pause for a set time | P or X gives the time; units depend on the control |
| G17 | Plane | XY plane | Default on mills |
| G18 | Plane | XZ plane | Default on lathes |
| G19 | Plane | YZ plane | |
| G20 | Units | Inch units | G70 on some controls |
| G21 | Units | Millimeter units | G71 on some controls |
| G28 | Reference | Return to the machine reference point | Usually through an intermediate point |
| G40 | Cutter compensation | Cancel cutter radius compensation | |
| G41 | Cutter compensation | Compensate left of the path | Climb milling with a right-hand cutter |
| G42 | Cutter compensation | Compensate right of the path | Conventional milling |
| G43 | Tool length | Apply tool length offset H | Mills |
| G49 | Tool length | Cancel tool length offset | |
| G53 | Coordinates | Move in machine coordinates | One line only (not modal) |
| G54 to G59 | Coordinates | Work offsets 1 to 6 | Select the part zero |
| G73 | Canned cycle | High-speed peck drilling | Short retracts to break the chip |
| G80 | Canned cycle | Cancel canned cycle | |
| G81 | Canned cycle | Drilling | Feed in, rapid out |
| G82 | Canned cycle | Drilling with dwell | Spot facing, counterboring |
| G83 | Canned cycle | Peck drilling | Full retract to clear chips |
| G84 | Canned cycle | Tapping | Right-hand thread |
| G85 | Canned cycle | Boring, feed in and feed out | Also reaming |
| G90 | Distance mode | Absolute positions | Measured from the work zero |
| G91 | Distance mode | Incremental positions | Measured from the current position |
| G92 | Coordinates | Set the current position value | G50 on many lathes, which also sets the spindle speed limit |
| G94 | Feed mode | Feed per minute | G98 on some lathes |
| G95 | Feed mode | Feed per revolution | G99 on some lathes |
| G96 | Spindle | Constant surface speed | Lathes; S is m/min or ft/min |
| G97 | Spindle | Constant spindle speed | S is rev/min |
| G98 | Canned cycle | Return to the initial level | Mills |
| G99 | Canned cycle | Return to the R level | Mills |
| M00 | Program | Program stop | Waits for cycle start |
| M01 | Program | Optional stop | Only if the optional-stop switch is on |
| M02 | Program | End of program | |
| M03 | Spindle | Spindle on, clockwise | With S for the speed |
| M04 | Spindle | Spindle on, counterclockwise | |
| M05 | Spindle | Spindle stop | |
| M06 | Tool | Tool change | With T for the tool number |
| M08 | Coolant | Flood coolant on | M07 is mist or through-tool on many machines |
| M09 | Coolant | Coolant off | |
| M30 | Program | End of program and rewind | |
| M98 | Program | Call a subprogram | P gives the program number |
| M99 | Program | Return from a subprogram | Or loop the main program |
Source and notes: ISO 6983 and the NIST RS274NGC interpreter for the common meanings; Fanuc-style conventions for the canned cycles. Controls differ, especially for M codes, lathe codes and codes above G100: the machine manual is the authority.
How to use this table
- Read a program line by line and look up any code you do not know. Leading zeros are optional: G1 and G01 are the same.
- Note the group. Only one code from a group is active at a time, so G01 cancels G00, and G91 cancels G90.
- Check the result before cutting: paste the program into the G-code Viewer to see the tool path and the cutting time.
Worked example: reading a short program
G21 G90 G54: millimeter units, absolute positions, first work offset.M03 S1200thenG00 X0 Y0 Z5: spindle on at 1,200 rev/min, rapid to 5 mm above the part zero.G01 Z-2 F100thenX50 F300: feed down 2 mm at 100 mm/min, then cut 50 mm along X at 300 mm/min. The second line has no G code because G01 is still active. That cut takes 50 ÷ 300 × 60 = 10 seconds.G00 Z5,M05,M30: retract, stop the spindle, end and rewind.
Notes and cautions
- Controls differ. The motion codes are nearly universal, but canned cycles, lathe codes and M codes vary between Fanuc, Haas, Siemens, Heidenhain, LinuxCNC, Grbl and others. The machine manual is the authority.
- On many lathes G98 and G99 select feed per minute and feed per revolution, and G50 sets the maximum spindle speed, where a mill uses the same numbers for something else.
- A missing modal code is a common cause of crashes: a move programmed after a G00 that was meant to be a G01 is made at rapid speed.
- 3D printers and laser cutters use the same G0 and G1 moves with their own M codes for heaters, fans and laser power.
Related tools and guides
- G-code Viewer
- G-code and Programming (CNC guide)
- CNC Feeds and Speeds Calculator
- All reference tables
FAQ
What is the difference between G00 and G01?
G00 moves as fast as the machine can go and is used only for positioning in clear air. G01 moves in a straight line at the programmed feed rate and is used for cutting.
What is the difference between G90 and G91?
In G90 coordinates are absolute positions from the work zero. In G91 they are distances from the current position.
What is the difference between M02 and M30?
Both end the program. M30 also rewinds to the start, ready to run again, and is the usual choice.
What do G54 to G59 do?
They select one of six stored work offsets, each of which defines where the part zero is on the machine table. They let one program run on several fixtures.
Sources
- ISO 6983-1, Automation systems and integration: numerical control of machines, program format and definitions of address words.
- Kramer, T. R., et al., The NIST RS274NGC Interpreter, Version 3.
- ISO 6983 and the NIST RS274NGC interpreter for the common meanings; Fanuc-style conventions for the canned cycles. Controls differ, especially for M codes, lathe codes and codes above G100: the machine manual is the authority.
