Common G-codes

Common G-codes

The common G-codes are the twenty or so that appear in almost every CNC program: G00 and G01 to move, G02 and G03 for arcs, G20/G21 for units, G90/G91 for absolute or incremental, G54 for the work offset, G43 for tool length and G41/G42/G40 for cutter compensation, plus the drilling cycles and G80. Learn what each does and you can read most beginner programs.

The core G-codes at a glance

These are the codes marked as core in our code bank: the ones a first program uses and a first test asks about. Each links to its own page with an example and the codes it gets confused with.

CodeNameWhat it does
G00Rapid positioningMoves to a point at full rapid speed, not cutting.
G01Linear interpolation (feed move)Cuts in a straight line at the programmed feed rate F.
G02Circular interpolation, clockwiseCuts an arc clockwise, seen from the positive end of the axis normal to the plane.
G03Circular interpolation, counterclockwiseCuts an arc counterclockwise.
G04DwellPauses motion for a set time; the spindle keeps running.
G20Inch unitsPrograms positions and feeds in inches.
G21Metric unitsPrograms positions and feeds in millimetres.
G28Return to reference positionSends the named axes home, by way of an intermediate point.
G40Cutter compensation cancelTurns off cutter radius (or tool nose) compensation.
G41Cutter compensation leftOffsets the tool to the left of the path, looking in the direction of travel.
G42Cutter compensation rightOffsets the tool to the right of the path.
G43Tool length compensation +Applies the tool length offset H so Z positions are measured from the tool tip.
G54Work offset 1Selects the first work coordinate system, where program zero is on the part.
G80Canned cycle cancelCancels the active drilling or tapping cycle.
G81Drilling cycle (spot drill)Feeds to depth and rapids out: one move per hole.
G83Deep hole peck drillingPecks Q deep and retracts fully out of the hole each time.
G84Tapping cycle (right hand)Taps to depth, reverses the spindle and feeds out.
G90Absolute positioningPositions are measured from program zero.
G91Incremental positioningPositions are distances from the current point.
G96Constant surface speedS is a cutting speed (m/min or ft/min); RPM changes with diameter.
G97Constant RPMS is a fixed spindle speed in RPM.

The full G-code list adds the advanced codes (rotation, polar coordinates, macro calls) and every lathe cycle.

Read them in a real program

A list only goes so far. Here is a short program for a vertical mill that drills two holes, with every line explained. Almost every core G-code appears in it.

LineWhat it does
%Start of the program file.
O1001 (FACE PLATE HOLES)Program number and a comment.
G21 G17 G40 G49 G80 G90The safety line: millimetres, XY plane, no cutter compensation, no tool length offset, no canned cycle, absolute positions. Whatever the last program left active is reset here.
T1 M06Load tool 1.
G54 G00 X0. Y0. S1200 M03Use work offset G54, rapid to program zero, start the spindle clockwise at 1200 RPM.
G43 H01 Z25. M08Turn on the length offset for tool 1 and move 25 mm above the part, coolant on.
G99 G81 X10. Y10. Z-5. R2. F120.Drilling cycle: feed to 5 mm deep at the first hole, return to the R plane 2 mm above the part.
X30.G81 is modal, so this line alone drills a second hole at X30 Y10.
G80 G00 Z25. M09Cancel the cycle, rapid up, coolant off.
G91 G28 Z0. M05Return Z straight home (G91 makes the intermediate point the current position), spindle off.
G90Back to absolute, so the next program does not start incremental.
M30End of program and rewind.
%End of the file.

Modal codes: why one line can do two things

Most G-codes are modal: once programmed, they stay active until another code from the same group replaces them. That is why X30. on its own drilled a second hole above: G81 was still active. It is also why a forgotten G91 turns every later position into a distance, a common cause of crashes. Non-modal codes such as G04 and G28 act only on their own line.

The pairs beginners mix up

  • G00 and G01: rapid positioning versus a cutting move at feed.
  • G02 and G03: clockwise versus counterclockwise arcs.
  • G41 and G42: compensation to the left or right of the path.
  • G43 and G41: tool length (H) versus tool radius (D).
  • G73 and G83: chip-breaking pecks versus full-retract pecks.
  • G90 and G91: absolute positions versus distances from here.

Quiz: the core G-codes

Ten questions. The wrong answers are the codes people really confuse.

Question 1 of 10Score 0

Mill and lathe: what does this code do?

G04

Keep going with saved progress and review of missed codes

More practice hubs

Frequently asked questions

What are the most common G-codes?
The G-codes in nearly every milling program are G00, G01, G02, G03, G04, G20, G21, G28, G40, G41, G42, G43, G54, G80, G81, G83, G84, G90, G91, G96, G97. They cover motion, units, offsets, compensation and the basic drilling cycles.
How many G-codes do I need to know as a beginner?
About twenty. Motion (G00 to G03), units (G20, G21), absolute and incremental (G90, G91), the work offset (G54), tool length and cutter compensation (G43, G40 to G42), the drilling cycles and G80, and G28. The rest you look up when a program uses them.
What is a safety line in G-code?
A line at the start of a program, or of each tool, that resets the modal codes to a known state, for example G21 G17 G40 G49 G80 G90. It stops a program inheriting a cycle, an offset or incremental mode from whatever ran before.
Are these G-codes the same on a lathe?
Motion, units, dwell and compensation are the same. Some numbers change on a lathe with Fanuc G-code system A: G90 is a turning cycle, G92 a threading cycle, and G98/G99 set the feed mode. Each code page shows both meanings where they differ.

G-Code Sprint is an educational practice tool only. It is not a CNC simulator, machine controller, safety manual, or replacement for instruction. Always follow your instructor, employer, machine manual, and shop procedures.

Free preview · no card Try G-Code Sprint