Complete CNC G-Code List: Every G-Code Explained with Examples
If you’re programming CNC machines, you need a reliable cnc g code list at your fingertips. G-codes are the language CNC controllers use to define motion, positioning, coordinate systems, and machining cycles. This reference covers every standard G-code from G00 through G99, organized by function with real examples, modal groups, and usage notes. Whether you’re writing programs by hand, debugging post-processor output, or learning CNC for the first time, this CNC G-code list is your go-to resource.
What is G-code in CNC machining?
G-code is a standardized programming language that tells CNC machines how to move and what operations to perform. Each G-code is a preparatory command that defines motion type (rapid, linear, arc), coordinate system, plane selection, work offsets, canned cycles, or compensation modes. G-codes are called “preparatory” because they prepare the controller for the type of motion or operation that follows.
A typical CNC program consists of G-codes (motion and setup), M-codes (machine functions like spindle on/off, coolant), coordinate values (X, Y, Z positions), and feed rates (F) or spindle speeds (S). G-codes are modal, meaning once activated, they remain in effect until replaced by another code in the same group. For example, G01 (linear interpolation) stays active for all subsequent moves until you call G00 (rapid) or G02 (arc).
G-code was standardized decades ago, but variations exist between controller manufacturers (Fanuc, Siemens, Heidenhain, Haas, Mazak). The core motion and positioning codes (G00, G01, G02, G03, G90, G91) are nearly universal, but some canned cycles, compensation modes, and advanced features differ. This cnc g code list focuses on the most widely supported codes across mills, lathes, and routers.
How to read this CNC G-code list
This reference organizes G-codes by function and includes:
- G-Code: The command number (e.g., G00, G54, G81).
- Function: What the code does in plain language.
- Group: Modal group membership. Codes in the same group are mutually exclusive. Non-modal codes execute once and don’t stay active.
- Example: A real G-code snippet showing typical usage.
- Notes: Compatibility notes, common pitfalls, or variations.
Modal groups are critical to understanding G-code behavior. For example, G00, G01, G02, and G03 are all in the motion group (Group 01). Only one can be active at a time. When you call G01, it cancels any previous G00, G02, or G03.
Common modal groups:
- Group 01 (Motion): G00, G01, G02, G03, G80–G89 (canned cycles).
- Group 02 (Plane selection): G17, G18, G19.
- Group 03 (Absolute/incremental): G90, G91.
- Group 05 (Feed rate mode): G93, G94, G95.
- Group 06 (Units): G20, G21.
- Group 07 (Cutter compensation): G40, G41, G42.
- Group 12 (Work offsets): G54–G59.
Non-modal codes (like G04, G28, G92) execute once and don’t affect subsequent lines.
When reading the table, pay attention to which group each code belongs to. If you accidentally call two codes from the same group on one line, the last one wins (or the controller throws an alarm).
Complete G-code list (full reference table)
| G-Code | Function | Group | Example | Notes |
| G00 | Rapid positioning (traverse) | 01 | G00 X10 Y20 Z5 | Non-cutting move at maximum feed rate; exact path not controlled |
| G01 | Linear interpolation (feed move) | 01 | G01 X50 Y30 F200 | Straight-line cutting move at specified feed rate |
| G02 | Circular interpolation CW | 01 | G02 X30 Y30 I10 J0 F150 | Clockwise arc; I/J specify arc center offset from start |
| G03 | Circular interpolation CCW | 01 | G03 X30 Y30 I10 J0 F150 | Counterclockwise arc; same syntax as G02 |
| G04 | Dwell (pause) | 00 | G04 P2000 | Pause for P milliseconds (or X seconds on some controls) |
| G09 | Exact stop check | 00 | G09 X10 Y10 | Forces deceleration to zero before next move (non-modal) |
| G10 | Programmable data input | 00 | G10 L2 P1 X0 Y0 Z0 | Set work offset values in program; syntax varies by control |
| G17 | XY plane selection | 02 | G17 | Default plane for most milling; arcs use I/J, tool comp in XY |
| G18 | XZ plane selection | 02 | G18 | Common for lathe operations; arcs use I/K |
| G19 | YZ plane selection | 02 | G19 | Less common; arcs use J/K |
| G20 | Inch units | 06 | G20 | All coordinates and feeds in inches |
| G21 | Metric units (mm) | 06 | G21 | All coordinates and feeds in millimeters |
| G28 | Return to home position | 00 | G28 Z0 | Moves through specified point then to machine home (non-modal) |
| G29 | Return from home position | 00 | G29 X10 Y10 | Move from home through intermediate point (rarely used) |
| G30 | Return to secondary home | 00 | G30 Z0 | Similar to G28 but to a second reference point |
| G40 | Cutter compensation cancel | 07 | G40 | Turn off cutter radius compensation (default) |
| G41 | Cutter compensation left | 07 | G41 D01 | Tool offsets to the left of programmed path |
| G42 | Cutter compensation right | 07 | G42 D01 | Tool offsets to the right of programmed path |
| G43 | Tool length offset + | 08 | G43 H01 Z5 | Apply tool length compensation from offset register H |
| G44 | Tool length offset – | 08 | G44 H01 Z5 | Rarely used; negative length offset (most controls use only G43) |
| G49 | Tool length offset cancel | 08 | G49 | Turn off tool length compensation |
| G50 | Coordinate system scaling off | 11 | G50 | Cancel scaling (or max spindle speed on lathes) |
| G51 | Coordinate system scaling on | 11 | G51 X2 Y2 | Scale all programmed coordinates by specified factor |
| G52 | Local coordinate system | 00 | G52 X10 Y10 | Shift origin temporarily; adds offset to active work coordinate |
| G53 | Machine coordinate system | 00 | G53 G00 X0 Y0 Z0 | Move in machine coordinates (non-modal, one-shot) |
| G54 | Work coordinate system 1 | 12 | G54 | Most common work offset; default on many controls |
| G55 | Work coordinate system 2 | 12 | G55 | Second work offset register |
| G56 | Work coordinate system 3 | 12 | G56 | Third work offset register |
| G57 | Work coordinate system 4 | 12 | G57 | Fourth work offset register |
| G58 | Work coordinate system 5 | 12 | G58 | Fifth work offset register |
| G59 | Work coordinate system 6 | 12 | G59 | Sixth work offset register |
| G61 | Exact stop mode | 13 | G61 | Controller decelerates to exact position at each endpoint |
| G64 | Continuous path mode | 13 | G64 | Controller blends moves for smooth contouring (default on most) |
| G68 | Coordinate rotation on | 16 | G68 X0 Y0 R45 | Rotate coordinate system by R degrees around specified point |
| G69 | Coordinate rotation off | 16 | G69 | Cancel coordinate rotation |
| G73 | High-speed peck drilling cycle | 01 | G73 X10 Y10 Z-20 Q5 R2 F100 | Pecking with small retract; clears chips without full retract |
| G74 | Left-hand tapping cycle | 01 | G74 X10 Y10 Z-20 R2 F100 | Reverse spindle tapping (rarely used; most use G84) |
| G76 | Fine boring cycle | 01 | G76 X10 Y10 Z-20 R2 F50 | Oriented spindle stop, shift away, then retract (for precision) |
| G80 | Canned cycle cancel | 01 | G80 | Cancel any active drilling, tapping, or boring cycle |
| G81 | Drilling cycle (simple) | 01 | G81 X10 Y10 Z-20 R2 F200 | Rapid to R, feed to Z, rapid out |
| G82 | Drilling cycle with dwell | 01 | G82 X10 Y10 Z-20 P500 R2 F200 | Like G81 but pauses at bottom for P milliseconds |
| G83 | Peck drilling cycle | 01 | G83 X10 Y10 Z-20 Q5 R2 F200 | Full retract pecking; Q = peck depth increment |
| G84 | Tapping cycle | 01 | G84 X10 Y10 Z-20 R2 F100 | Synchronized feed/spindle for tapping; rigid or tension/compression |
| G85 | Boring cycle (feed in and out) | 01 | G85 X10 Y10 Z-20 R2 F100 | Feed in, feed out at same rate (no spindle stop) |
| G86 | Boring cycle (feed in, rapid out) | 01 | G86 X10 Y10 Z-20 R2 F100 | Feed to depth, spindle stop, rapid retract |
| G87 | Back boring cycle | 01 | G87 X10 Y10 Z-20 R2 F100 | Complex cycle for boring from back side; rarely used |
| G88 | Boring cycle with dwell | 01 | G88 X10 Y10 Z-20 P1000 R2 F100 | Feed in, dwell, manual retract (uncommon) |
| G89 | Boring cycle with dwell, feed out | 01 | G89 X10 Y10 Z-20 P500 R2 F100 | Feed in, dwell at bottom, feed out |
| G90 | Absolute positioning mode | 03 | G90 | All coordinates relative to work coordinate origin (default) |
| G91 | Incremental positioning mode | 03 | G91 | All coordinates relative to current position |
| G92 | Set work coordinate offset | 00 | G92 X0 Y0 Z0 | Redefine current position as specified coordinates (use carefully) |
| G94 | Feed per minute mode | 05 | G94 | Feed rate in units/min (default on mills) |
| G95 | Feed per revolution mode | 05 | G95 | Feed rate in units/revolution (common on lathes) |
| G98 | Return to initial Z level (canned cycles) | 10 | G98 | After cycle, retract to Z position before cycle started |
| G99 | Return to R level (canned cycles) | 10 | G99 | After cycle, retract only to R plane (faster for multiple holes) |
This table covers the most common G-codes on mills, lathes, and routers. Some advanced codes (G96 constant surface speed, G15/G16 polar coordinates, G65 macro call) are control-dependent and not shown here. Always consult your specific controller manual for full syntax and availability.
Motion G-codes (G00, G01, G02, G03)
Motion codes control how the tool moves from one point to another. These are the most frequently used commands in any CNC program.
G00 – Rapid positioning. Moves the tool at maximum traverse speed along the shortest path. Used for non-cutting repositioning. The path is not controlled — axes may move independently and not follow a straight line in multi-axis space. Never use G00 when the tool is cutting.
gcode
G00 X50 Y30 Z10
This moves rapidly to X50, Y30, Z10 in the current work coordinate system. Feed rate (F) is ignored; the machine uses its maximum rapid rate.
G01 – Linear interpolation. Moves the tool in a straight line at a controlled feed rate. Used for cutting operations. The controller synchronizes all axes to produce a straight path in the specified plane.
gcode
G01 X100 Y50 F250
Feeds to X100, Y50 at 250 units per minute (or per revolution if G95 is active). All axes reach the endpoint simultaneously.
G02 – Circular interpolation, clockwise. Cuts an arc in the active plane (G17/G18/G19). Arc center is defined using I, J, K offsets (incremental from start point) or R radius.
gcode
G17 G02 X50 Y50 I25 J0 F200
From the current position, this cuts a clockwise arc to X50, Y50. The arc center is offset I25 (in X) and J0 (in Y) from the starting point. In G17 (XY plane), I = X offset, J = Y offset.
G03 – Circular interpolation, counterclockwise. Identical to G02 but arcs in the opposite direction.
gcode
G17 G03 X50 Y50 I25 J0 F200
Arc direction depends on plane selection. An arc that is clockwise when viewed from the positive Z axis (G17) may appear counterclockwise from the negative Z side. Always visualize from the perspective of the positive axis perpendicular to the plane.
Common arc syntax:
- I, J, K method: I/J/K are incremental offsets from the start point to the arc center. In G17, use I and J. In G18, use I and K. In G19, use J and K.
- R method: Specify radius directly: G02 X50 Y50 R25 F200. Simpler but ambiguous for arcs greater than 180° (some controls support R negative for the longer arc).
The I/J/K method is more robust and recommended for CAM-generated code. The R method is convenient for manual programming of simple arcs.
Plane selection, units & positioning (G17–G21, G90/G91)
Before motion commands can execute correctly, the controller needs to know which plane arcs operate in, what units are active, and whether coordinates are absolute or incremental.
G17, G18, G19 – Plane selection
- G17: XY plane (Z perpendicular). Default on vertical mills. Arcs use I (X offset) and J (Y offset).
- G18: XZ plane (Y perpendicular). Common on lathes and horizontal mills. Arcs use I (X offset) and K (Z offset).
- G19: YZ plane (X perpendicular). Rarely used. Arcs use J (Y offset) and K (Z offset).
Plane selection also affects cutter radius compensation (G41/G42) and tool tip radius compensation on lathes. Always confirm the correct plane is active before circular moves.
gcode
G17
G02 X30 Y30 I10 J0 F150
This cuts a clockwise arc in the XY plane.
G20, G21 – Units
- G20: Inch mode. All coordinates, feed rates, and offsets are in inches.
- G21: Metric mode. All values in millimeters.
These codes are modal and typically set at the program start. Switching units mid-program is possible but rarely done because it complicates offsets and feeds.
gcode
G21 ; metric mode
G01 X100 Y50 F500 ; 100mm, 500mm/min
G90, G91 – Absolute vs. incremental positioning
- G90: Absolute mode. Coordinates are relative to the active work offset origin (G54, etc.). Default on most machines.
- G91: Incremental mode. Coordinates are relative to the current tool position.
gcode
G90 ; absolute
G01 X50 Y30 ; move to X50, Y30 in work coordinates
G91 ; incremental
G01 X10 Y5 ; move +10 in X and +5 in Y from current position
Incremental mode is useful for repetitive patterns or when programming relative to an unknown starting position. Most CAM systems output absolute (G90) code by default. Mixing G90 and G91 carelessly causes positioning errors, so use G91 intentionally and return to G90 when done.
Work offsets & coordinate systems (G54–G59)
Work offsets let you define part zero independently of machine home. Without them, every program would reference machine coordinates, and changing part location would require rewriting the program.
G54 through G59 activate stored work coordinate systems. Each offset (G54, G55, G56, etc.) holds X, Y, Z values that define where the part origin is in machine coordinates. When G54 is active and you command X0 Y0 Z0, the machine moves to the position defined in the G54 offset register.
Typical workflow:
- Indicate or probe the part to find part zero.
- Record the machine coordinates of part zero.
- Store those coordinates in a work offset register (G54).
- Call G54 in the program.
- All subsequent coordinates are relative to that origin.
gcode
G54 ; activate work offset 1
G00 X0 Y0 Z10 ; rapid to part zero plus 10mm in Z
You can store multiple part origins in different registers and switch between them in a single program. This is common for tombstone fixtures or multi-part setups.
gcode
G54 ; first part
; machine first part
G55 ; second part
; machine second part
G52 is a local coordinate shift that temporarily offsets the active work coordinate (G54, etc.) without modifying the stored offset. Useful for sub-programs or pocketing routines. G52 is additive and canceled by calling G52 with no parameters or at program end.
G53 is a non-modal command that makes the next move happen in machine coordinates, ignoring all work offsets. Used for safe retracts to known machine positions.
gcode
G53 G00 Z0 ; rapid Z to machine home, ignoring work offset
Use G53 carefully — coordinates are in machine space, not part space. Calling G53 X0 Y0 sends the machine to the machine home origin, which may be far from your part.
Canned cycles for drilling & tapping (G81–G89)
Canned cycles automate repetitive operations like drilling, tapping, and boring. Instead of programming every Z feed, retract, and dwell manually, you call a G8x code once and the controller executes a multi-step sequence.
Common parameters:
- X, Y: Hole location.
- Z: Final depth.
- R: Retract plane (safe height above part surface).
- Q: Peck increment (for G73, G83).
- P: Dwell time in milliseconds (for G82, G88, G89).
- F: Feed rate.
G81 – Simple drilling cycle. Rapid to R, feed to Z, rapid back out.
gcode
G90 G54 G00 X10 Y10
G81 Z-15 R2 F200
X20 Y10
X30 Y10
G80 ; cancel cycle
After calling G81, every subsequent XY move drills a hole at the new position with the same Z, R, F. This eliminates repetitive Z plunges.
G82 – Drilling with dwell. Like G81 but pauses at the bottom (P parameter) to clear chips or break edges.
gcode
G82 X10 Y10 Z-15 R2 P500 F200
Dwells for 500 milliseconds at full depth before retracting.
G83 – Peck drilling cycle. For deep holes. Retracts fully after each peck to clear chips.
gcode
G83 X10 Y10 Z-50 Q5 R2 F150
Pecks in Q5 increments (5mm per peck), fully retracts between pecks, until reaching Z-50. Prevents chip packing and tool breakage in deep holes.
G73 – High-speed peck drilling. Similar to G83 but retracts only a small distance (partial retract) to break chips without fully exiting the hole. Faster than G83 but requires good chip evacuation.
G84 – Tapping cycle. Synchronizes spindle speed and feed rate to cut threads. Requires rigid tapping (spindle encoder feedback) or tension/compression tap holders.
gcode
G84 X10 Y10 Z-20 R2 F100
Feed rate F must match the thread pitch and spindle speed: . For M6x1.0 thread at 1000 RPM: mm/min.
The controller reverses the spindle and retracts at the same pitch to back the tap out. Do not use cutter compensation (G41/G42) with G84.
G85 through G89 are boring cycles with variations in retract and dwell. G85 feeds in and out. G86 feeds in, stops spindle, rapids out. G89 feeds in, dwells, feeds out. Boring cycles are less common than drilling and used primarily for precision holes.
Canceling canned cycles: Use G80 to deactivate any active cycle. After G80, XY moves no longer trigger drilling. Always cancel the cycle before moving to a new operation or end of program.
G98 vs. G99: Controls retract behavior.
- G98: Retract to the initial Z position (where you were before calling the canned cycle). Safe but slower.
- G99: Retract only to R plane. Faster for multiple holes at the same Z level but requires careful R plane setting.
gcode
G98 G83 X10 Y10 Z-30 Q5 R2 F200 ; retract to initial Z after each hole
G99 G83 X20 Y10 ; retract to R2 after this hole
Tool & cutter compensation (G40–G43)
Compensation codes allow you to program the part geometry directly and let the controller offset the tool path by the tool radius (cutter comp) or length (tool length offset).
G40, G41, G42 – Cutter radius compensation
Cutter compensation offsets the tool path perpendicular to the programmed path by the tool radius, so you can program the part boundary without calculating tool center paths.
- G40: Compensation off (default).
- G41: Compensation left. Tool moves to the left of the programmed path (when facing the direction of travel).
- G42: Compensation right. Tool moves to the right of the programmed path.
The offset distance comes from a tool offset register (D number) stored in the controller.
gcode
G01 G41 D01 X20 Y10 F300 ; engage comp left, tool offset D01
X50 Y10
X50 Y40
X20 Y40
X20 Y10
G01 G40 X10 Y10 ; cancel comp
Use a lead-in move when engaging G41/G42 (don’t start compensation in an arc or tangent to a corner). Similarly, use a lead-out move when canceling. The controller needs at least one linear move to calculate the offset path.
Cutter compensation is modal and remains active until canceled with G40. Compensation type (left/right) and offset number (D) are set together but only the offset distance is stored in the D register. If you change tools and the diameter changes, update the D offset value; you don’t need to rewrite the program.
G43, G49 – Tool length compensation
Tool length offset adjusts Z position to account for different tool lengths. Without it, you’d need to touch off every tool individually and store separate Z offsets.
- G43 H__: Apply tool length offset from H register. Typically, H matches the tool number (T1 uses H1).
- G49: Cancel tool length offset.
gcode
G43 H01 Z10 ; apply length offset H01, move to Z10 (part coordinate)
The H register stores the offset distance (usually measured during tool setup using a tool setter or probe). When G43 is active, the controller adds the H offset to all programmed Z values.
Tool length compensation is modal. Call G43 after every tool change (usually in the tool change macro or immediately after M06). Cancel it with G49 at program end or before returning to machine coordinates (G53).
gcode
T01 M06 ; load tool 1
G43 H01 Z50 ; apply length offset, rapid to Z50
; machining moves
G49 ; cancel offset before tool change
T02 M06
G43 H02 Z50
Some controllers support G43.4 or G43.1 for dynamic tool length measurement or 3D tool comp. These are advanced features; check your controller documentation.
Common G-code programming examples
Example 1: Simple rectangular pocket
gcode
G90 G54 G17 ; absolute, work offset 1, XY plane
G00 X0 Y0 Z10 ; rapid to start, safe Z
G01 Z-5 F100 ; plunge to depth
G41 D01 X10 Y10 F300 ; engage comp, move to corner
X40 Y10 ; cut to next corner
X40 Y30
X10 Y30
X10 Y10 ; close rectangle
G40 G01 X0 Y0 ; cancel comp, retract
G00 Z10
M30 ; end program
Example 2: Drilling a bolt circle
gcode
G90 G54 G00 X0 Y0 Z10
G81 Z-20 R2 F200 ; drill cycle
X30 Y0 ; hole 1
X21.21 Y21.21 ; hole 2
X0 Y30 ; hole 3
X-21.21 Y21.21 ; hole 4
X-30 Y0 ; hole 5
X-21.21 Y-21.21 ; hole 6
X0 Y-30 ; hole 7
X21.21 Y-21.21 ; hole 8
G80 ; cancel cycle
G00 Z50
M30
Example 3: Arc cuts with plane selection
gcode
G90 G54 G17 ; XY plane
G00 X0 Y0 Z5
G01 Z0 F100
G02 X20 Y20 I10 J0 F250 ; CW arc, center at X10 Y0 from start
G01 X40 Y20
G03 X40 Y0 I0 J-10 F250 ; CCW arc, center offset in Y
G01 X0 Y0
G00 Z10
M30
Example 4: Incremental pocketing
gcode
G90 G54 G00 X25 Y25 Z10
G01 Z-5 F100
G91 ; incremental mode
G01 X10 F300
Y10
X-10
Y-10 ; square spiral
G90 ; back to absolute
G00 Z10
M30
G-code vs. M-code: what’s the difference?
G-codes are preparatory functions. They define motion type, coordinate systems, planes, offsets, and machining cycles. G-codes set up how the machine will move.
M-codes are miscellaneous functions. They control machine auxiliary functions: spindle on/off (M03/M05), coolant on/off (M07/M08/M09), tool changes (M06), program stop (M00/M01), program end (M30). M-codes control what the machine does around the motion.
A typical CNC block contains both:
gcode
G01 X50 Y30 F250 M08
G01 defines linear motion. M08 turns coolant on. Both execute on the same line, but conceptually they control different aspects of the operation.
Some M-codes are modal (M03 spindle on stays active until M05), others are non-modal (M06 tool change executes once). M-code groups prevent conflicting commands (you can’t have M03 and M04 active simultaneously).
In general:
- G-codes = motion, positioning, geometry.
- M-codes = machine state, auxiliary hardware.
Both are essential. A complete CNC program uses G-codes for the toolpath and M-codes for machine control.
Frequently Asked Questions
What is the most common G-code?
G01 (linear interpolation) is the most common. It defines straight-line cutting moves at a controlled feed rate. Almost every CNC program uses G01 extensively.
Are G-codes the same on all CNC machines?
Core motion codes (G00, G01, G02, G03, G90, G91) are nearly universal across Fanuc, Siemens, Haas, Mazak, and other controls. However, advanced features like canned cycles, macros, and compensation modes vary. Always verify codes against your specific controller manual.
What does the “G” in G-code stand for?
“G” stands for “general” or “geometric,” indicating preparatory functions related to motion and geometry. M-codes (miscellaneous) control auxiliary functions. The terminology dates back to early NC standards in the 1950s–60s.
Can I mix G90 and G91 in the same program?
Yes, but carefully. Switching between absolute (G90) and incremental (G91) mid-program is allowed and useful for specific patterns or subprograms. Always explicitly set the mode before moves that depend on it, and return to G90 when done to avoid confusion.
How do I know which work offset (G54, G55, etc.) to use?
G54 is the default and most commonly used. Use additional offsets (G55–G59) when running multiple parts on one setup or when switching between fixtures. The offset you choose depends on your setup strategy; there’s no inherent difference between them beyond the stored coordinate values.
What’s the difference between G02 and G03?
G02 is clockwise arc interpolation, G03 is counterclockwise. Direction is defined by looking down the positive axis perpendicular to the active plane. In G17 (XY plane), viewing from +Z, G02 arcs clockwise and G03 counterclockwise.
This cnc g code list is a living reference. Bookmark it, print it, or keep it open in a browser tab while programming. G-codes are the foundation of CNC machining, and understanding them fully separates operators who troubleshoot effectively from those who just push cycle start.