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

46 rows
CodeGroupMeaningNotes
G00MotionRapid positioningMoves at the machine's rapid rate; not for cutting
G01MotionLinear move at feed rate FStraight-line cutting
G02MotionCircular move, clockwiseCenter by I, J, K or radius R
G03MotionCircular move, counterclockwiseCenter by I, J, K or radius R
G04DwellPause for a set timeP or X gives the time; units depend on the control
G17PlaneXY planeDefault on mills
G18PlaneXZ planeDefault on lathes
G19PlaneYZ plane
G20UnitsInch unitsG70 on some controls
G21UnitsMillimeter unitsG71 on some controls
G28ReferenceReturn to the machine reference pointUsually through an intermediate point
G40Cutter compensationCancel cutter radius compensation
G41Cutter compensationCompensate left of the pathClimb milling with a right-hand cutter
G42Cutter compensationCompensate right of the pathConventional milling
G43Tool lengthApply tool length offset HMills
G49Tool lengthCancel tool length offset
G53CoordinatesMove in machine coordinatesOne line only (not modal)
G54 to G59CoordinatesWork offsets 1 to 6Select the part zero
G73Canned cycleHigh-speed peck drillingShort retracts to break the chip
G80Canned cycleCancel canned cycle
G81Canned cycleDrillingFeed in, rapid out
G82Canned cycleDrilling with dwellSpot facing, counterboring
G83Canned cyclePeck drillingFull retract to clear chips
G84Canned cycleTappingRight-hand thread
G85Canned cycleBoring, feed in and feed outAlso reaming
G90Distance modeAbsolute positionsMeasured from the work zero
G91Distance modeIncremental positionsMeasured from the current position
G92CoordinatesSet the current position valueG50 on many lathes, which also sets the spindle speed limit
G94Feed modeFeed per minuteG98 on some lathes
G95Feed modeFeed per revolutionG99 on some lathes
G96SpindleConstant surface speedLathes; S is m/min or ft/min
G97SpindleConstant spindle speedS is rev/min
G98Canned cycleReturn to the initial levelMills
G99Canned cycleReturn to the R levelMills
M00ProgramProgram stopWaits for cycle start
M01ProgramOptional stopOnly if the optional-stop switch is on
M02ProgramEnd of program
M03SpindleSpindle on, clockwiseWith S for the speed
M04SpindleSpindle on, counterclockwise
M05SpindleSpindle stop
M06ToolTool changeWith T for the tool number
M08CoolantFlood coolant onM07 is mist or through-tool on many machines
M09CoolantCoolant off
M30ProgramEnd of program and rewind
M98ProgramCall a subprogramP gives the program number
M99ProgramReturn from a subprogramOr 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

  1. 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.
  2. Note the group. Only one code from a group is active at a time, so G01 cancels G00, and G91 cancels G90.
  3. 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 S1200 then G00 X0 Y0 Z5: spindle on at 1,200 rev/min, rapid to 5 mm above the part zero.
  • G01 Z-2 F100 then X50 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.

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.

Published by Nick Peterson, mechanical engineer.