Common G-codes
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.
| Code | Name | What it does |
|---|---|---|
G00 | Rapid positioning | Moves to a point at full rapid speed, not cutting. |
G01 | Linear interpolation (feed move) | Cuts in a straight line at the programmed feed rate F. |
G02 | Circular interpolation, clockwise | Cuts an arc clockwise, seen from the positive end of the axis normal to the plane. |
G03 | Circular interpolation, counterclockwise | Cuts an arc counterclockwise. |
G04 | Dwell | Pauses motion for a set time; the spindle keeps running. |
G20 | Inch units | Programs positions and feeds in inches. |
G21 | Metric units | Programs positions and feeds in millimetres. |
G28 | Return to reference position | Sends the named axes home, by way of an intermediate point. |
G40 | Cutter compensation cancel | Turns off cutter radius (or tool nose) compensation. |
G41 | Cutter compensation left | Offsets the tool to the left of the path, looking in the direction of travel. |
G42 | Cutter compensation right | Offsets the tool to the right of the path. |
G43 | Tool length compensation + | Applies the tool length offset H so Z positions are measured from the tool tip. |
G54 | Work offset 1 | Selects the first work coordinate system, where program zero is on the part. |
G80 | Canned cycle cancel | Cancels the active drilling or tapping cycle. |
G81 | Drilling cycle (spot drill) | Feeds to depth and rapids out: one move per hole. |
G83 | Deep hole peck drilling | Pecks Q deep and retracts fully out of the hole each time. |
G84 | Tapping cycle (right hand) | Taps to depth, reverses the spindle and feeds out. |
G90 | Absolute positioning | Positions are measured from program zero. |
G91 | Incremental positioning | Positions are distances from the current point. |
G96 | Constant surface speed | S is a cutting speed (m/min or ft/min); RPM changes with diameter. |
G97 | Constant RPM | S 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.
| Line | What it does |
|---|---|
% | Start of the program file. |
O1001 (FACE PLATE HOLES) | Program number and a comment. |
G21 G17 G40 G49 G80 G90 | The 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 M06 | Load tool 1. |
G54 G00 X0. Y0. S1200 M03 | Use work offset G54, rapid to program zero, start the spindle clockwise at 1200 RPM. |
G43 H01 Z25. M08 | Turn 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. M09 | Cancel the cycle, rapid up, coolant off. |
G91 G28 Z0. M05 | Return Z straight home (G91 makes the intermediate point the current position), spindle off. |
G90 | Back to absolute, so the next program does not start incremental. |
M30 | End 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.
Mill and lathe: what does this code do?
G04
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.