Complete G-Code List: CNC Programming Reference
G-code (Geometric code) is the programming language that tells a CNC machine where to move, how fast to move, and what path to follow. Think of it as giving your machine a set of coordinates — and it moves the tool to those coordinates with perfect precision every time.
A single G-code line breaks down like this:
G01 X100 Y50 Z-5 F200
| Part | Meaning |
|---|---|
| G01 | Command: linear feed move |
| X100 Y50 Z-5 | Target coordinates |
| F200 | Feed rate: 200 mm/min |
This page covers every G-code you’ll ever need — from the 15 essential codes you’ll use daily to the full reference table organized by functional group, plus controller-specific differences and real mistakes to avoid. Bookmark this page and come back every time you write a CNC program.
Essential G-Codes Every CNC Programmer Must Know
You can write 90% of CNC programs with just these 15 codes. Master these first the rest will follow naturally.
| Code | Function | Example | When You Use It |
|---|---|---|---|
| G00 | Rapid positioning | G00 X100 Y50 |
Moving to a position without cutting |
| G01 | Linear feed (cutting) | G01 X100 F200 |
Cutting a straight line |
| G02 | Arc clockwise | G02 X100 Y50 R25 |
Cutting an arc or fillet |
| G03 | Arc counterclockwise | G03 X100 Y50 R25 |
Cutting an arc in reverse |
| G17 | XY plane (default) | G17 |
Milling operations |
| G20 | Inch mode | G20 |
Programming in inches |
| G21 | Metric mode | G21 |
Programming in millimeters |
| G40 | Cancel cutter comp | G40 |
Turning off radius offset |
| G43 | Tool length offset (+) | G43 H1 |
Activating a tool’s length |
| G54 | Work offset 1 | G54 |
Picking your part zero |
| G81 | Simple drill cycle | G81 R2 Z-10 F150 |
Drilling a standard hole |
| G83 | Peck drill cycle | G83 R2 Z-25 Q5 F120 |
Drilling a deep hole |
| G90 | Absolute positioning | G90 |
Coordinates from part zero |
| G91 | Incremental positioning | G91 |
Coordinates from current position |
| G94 | Feed per minute | G94 |
Standard feed rate mode |
G-Code Decision Flowchart
Not sure which motion code to use? Follow this simple decision tree:
graph TD
A{What do you want<br>the tool to do?} --> B{Is the tool<br>cutting material?}
B -->|No, just positioning| C[Use **G00** Rapid]
B -->|Yes, cutting| D{What shape?}
D -->|Straight line| E[Use **G01** Linear Feed]
D -->|Arc or circle| F{Which direction?}
F -->|Clockwise| G[Use **G02**]
F -->|Counterclockwise| H[Use **G03**]
C --> I[Keep G00 moves<br>above the workpiece]
E --> J[Set feed rate F<br>before cutting]
Modal vs One-Shot Codes
G-codes come in two types. Understanding the difference between them prevents crashes.
Modal codes stay active until you change them. You write them once and they affect every following line:
G90 G01 X50 F200 ; G90 and G01 are now active
X100 ; Still G90 + G01 → absolute linear move to X100
Y50 ; Still G90 + G01 → absolute linear move to Y50
One-shot codes only affect the line they are on:
G04 P1000 ; Dwell for 1 second — only this line
G81 R2 Z-10 F150 ; Drill cycle — cancels after G80
💡 Pro tip: Always set your mode explicitly at the start of each program. Never assume what mode the previous program left the machine in. This is called a safety block and it saves tools:
G90 G94 G17 G54
Complete G-Code Reference Table
All G-codes listed by functional group. Most groups are modal — once selected the code stays active until another code in the same group replaces it.
Group 01: Motion Codes
| Code | Description | Modal | Example |
|---|---|---|---|
| G00 | Rapid positioning | Yes | G00 X100 Y50 |
| G01 | Linear interpolation (feed) | Yes | G01 X100 F200 |
| G02 | Circular interpolation CW | Yes | G02 X100 Y50 R25 |
| G03 | Circular interpolation CCW | Yes | G03 X100 Y50 I25 J0 |
| G04 | Dwell (pause) | No | G04 P1000 (wait 1000ms) |
| G09 | Exact stop check | No | G09 G01 X100 |
For full circles always use IJK format not R. The R method cannot create a complete circle. IJK defines the center point relative to the start position giving you full 360-degree control.
Group 02: Plane Selection
| Code | Description | Modal | Default Machine |
|---|---|---|---|
| G17 | XY plane | Yes | Mills |
| G18 | XZ plane | Yes | Lathes |
| G19 | YZ plane | Yes | Rare |
Group 03: Distance Mode
| Code | Description | Modal | Example |
|---|---|---|---|
| G90 | Absolute positioning | Yes | G90 G01 X50 → move to X=50 |
| G91 | Incremental positioning | Yes | G91 G01 X50 → move +50 from here |
G90 (Absolute) G91 (Incremental)
───┬───┬───┬───┬─── ───┬───┬───┬───┬───
0 25 50 75 100 0 25 50 75 100
↑ ← Tool at 25 ↑ ← Tool at 25
G90 X75 → Tool goes TO 75 G91 X50 → Tool moves +50 to 75
🚨 Beginner mistake: Forgetting to switch back from G91. If you use G91 in a subprogram and do not end with G90 your next tool position will shift by the incremental amount. Always end subprograms with
G90before returning to the main program line.
Group 05: Feed Rate Mode
| Code | Description | Modal | Notes |
|---|---|---|---|
| G94 | Feed per minute | Yes | Standard for mills |
| G95 | Feed per revolution | Yes | Standard for lathes |
Group 06: Units
| Code | Description | Modal |
|---|---|---|
| G20 | Inch mode | Yes |
| G21 | Metric mode (millimeters) | Yes |
Group 07: Cutter Compensation
| Code | Description | Modal | When to Use |
|---|---|---|---|
| G40 | Cancel cutter comp | Yes | Default — no offset |
| G41 | Cutter compensation left | Yes | Tool is left of the profile |
| G42 | Cutter compensation right | Yes | Tool is right of the profile |
G41 D1 G01 X50 F200 ; Activate comp for tool 1 offset left
G40 G00 Z5 ; Cancel comp before retracting
🚨 Beginner mistake: Activating G41 or G42 without a G01 move on the same line causes an alarm. Always pair activation with a linear feed move so the controller can calculate the offset direction.
Group 08: Tool Length Offset
| Code | Description | Modal |
|---|---|---|
| G43 | Tool length offset (positive) | Yes |
| G44 | Tool length offset (negative) | Yes |
| G49 | Cancel tool length offset | Yes |
Group 09: Canned Cycles (Drilling)
| Code | Description | Example | Best For |
|---|---|---|---|
| G73 | Chip breaking (peck) | G73 R2 Z-25 Q5 F120 |
Deep holes small chips |
| G81 | Simple drilling | G81 R2 Z-10 F150 |
Standard hole |
| G82 | Spot drill with dwell | G82 R2 Z-5 P500 F100 |
Counterbores and spotfaces |
| G83 | Peck drilling (full retract) | G83 R2 Z-40 Q8 F120 |
Deep holes clear chips |
| G84 | Rigid tapping | G84 R2 Z-20 F500 |
Threading holes |
| G85 | Boring (feed out) | G85 R2 Z-30 F120 |
Precision bores |
| G86 | Boring (rapid out) | G86 R2 Z-30 F120 |
Rough boring |
| G89 | Boring with dwell | G89 R2 Z-30 P500 F120 |
Bottom finish |
Cancel any canned cycle with: G80
Group 12: Work Offsets
| Code | Description | Used For |
|---|---|---|
| G54 | Work offset 1 | Primary part position |
| G55 | Work offset 2 | Second part or operation |
| G56 | Work offset 3 | Third setup |
| G57 | Work offset 4 | Fourth setup |
| G58 | Work offset 5 | Fifth setup |
| G59 | Work offset 6 | Sixth setup |
Other Useful G-Codes
| Code | Description | Notes |
|---|---|---|
| G28 | Return to home position | G28 G91 Z0 — safe retract then home |
| G30 | Return to 2nd home | Tool change position |
| G50 | Max spindle speed (lathe) | G50 S3000 limits to 3000 RPM |
| G92 | Set coordinate offset | Use sparingly — prefer G54 |
| G96 | Constant surface speed (lathe) | G96 S150 M03 |
| G97 | Cancel CSS (lathe) | G97 S1200 M03 |
| G98 | Return to initial Z level | Safer for canned cycles (clears obstacles) |
| G99 | Return to R plane | Faster for canned cycles |
G-Code by Controller: What’s Different
Most G-codes are universal but each controller has its own quirks. Here is what to watch for when switching between machines:
| Code | Fanuc | Haas | GRBL | LinuxCNC |
|---|---|---|---|---|
| G28 | Standard | Same as Fanuc | Not supported | Works |
| G30 | 2nd reference point | Same | Not supported | G28.1 |
| G43 | Tool length on | Same | Not needed | Same |
| G52 | Local coordinate | Same | Limited | Limited |
| G53 | Machine coordinates | Same | Works | Works |
| G73 | Chip breaking | Same | Limited | Works |
| G84 | Rigid tap | Same | Not supported | Works |
| G96 | CSS | Same | Not supported | Works |
💡 Rule of thumb: Fanuc is the industry standard. Haas is very similar with minor extensions. GRBL is a simplified subset of about 30 codes. LinuxCNC is the most flexible but uses unique syntax for advanced features like parametric programming.
Common G-Code Mistakes Beginners Make
1. Using G00 When the Tool is in the Material
; ❌ WRONG — G00 is rapid speed and will crash
G00 Z-5 F100
; ✅ RIGHT — use G01 to feed into material
G01 Z-5 F100
What happened: The tool plunged into the workpiece at maximum machine speed. A 6mm end mill does not survive this. Neither does the workpiece.
2. Forgetting to Cancel G91 After a Subprogram
; Subprogram using incremental mode
O1000
G91 G01 X10
Y10
M99
; Back in main program — G91 is STILL ACTIVE!
; Your next G90 move is now interpreted as incremental.
Fix: Always end subprograms by switching back to absolute mode:
O1000
G91 G01 X10
Y10
G90 ; Switch back BEFORE returning
M99
3. Activating Cutter Compensation Without a Feed Move
; ❌ WRONG — this triggers an alarm
G41 G00 X50
; ✅ RIGHT — activate compensation with a feed move
G41 G01 X50 F200
Why it happens: Cutter compensation needs a feed move to calculate which direction to offset the tool path. A rapid move at G00 speed does not provide enough information.
4. Confusing G98 vs G99 in Canned Cycles
G81 R2 Z-10 F150 ; Returns to R plane (Z2) by default
G98 G81 R2 Z-10 F150 ; Returns to initial Z level (safer)
G99 G81 R2 Z-10 F150 ; Returns to R plane (faster)
Which one should you use: G98 when you need to clear clamps or obstacles above the part. G99 when the surface is open and you want to save cycle time.
5. Using G92 Instead of G54 for Work Offsets
; ❌ WRONG — G92 is temporary lost on reset
G92 X0 Y0 Z0
; ✅ RIGHT — use G54 work offset
G54 G00 X0 Y0 Z0
Why it matters: G92 shifts the coordinate system temporarily. If you hit the reset button or restart the program G92 is gone and your zero position moves. G54 stores the offset permanently in the controller memory.
G-Code Quick Reference: Cheatsheet
A print-friendly quick reference for daily use:
MOTION MODAL EXAMPLE
G00 Rapid Yes G00 X100
G01 Linear Feed Yes G01 X100 F200
G02 Arc CW Yes G02 X100 R25
G03 Arc CCW Yes G03 X100 I25
G04 Dwell No G04 P1000
PLANE MODAL DEFAULT
G17 XY Yes Mills
G18 XZ Yes Lathes
G19 YZ Yes Rare
MODE MODAL BEHAVIOR
G90 Absolute Yes Go TO coordinate
G91 Incremental Yes Move BY amount
UNITS MODAL
G20 Inches Yes
G21 Millimeters Yes
CUTTER COMP MODAL
G40 Cancel Yes
G41 Left Yes
G42 Right Yes
TOOL OFFSET MODAL
G43 Length + Yes
G49 Cancel Yes
CANNED CYCLES SYNTAX
G81 Simple drill G81 R2 Z-10 F150
G83 Peck drill G83 R2 Z-40 Q8 F120
G84 Rigid tap G84 R2 Z-20 F500
G80 Cancel Always close with G80
WORK OFFSETS RANGE
G54-G59 Six part zero positions
SAFETY BLOCK Always start with this:
G90 G94 G17 G54 (absolute, feed/min, XY plane, offset 1)
Frequently Asked Questions
How many G-codes are there in total?
About 100 G-codes exist across all controller dialects. Most programmers only use 15 to 20 regularly. The full Fanuc set includes roughly 85 codes. GRBL supports about 30. LinuxCNC supports the most including parametric macros and NURBS interpolation.
What is the difference between G-code and M-code?
G-code controls geometry — where the tool moves and what path it follows. M-code controls machine functions — spindle on or off, coolant flow, tool changes, and program flow.
G01 X100 F200 ; G-code: move the tool along a path
M03 S3000 ; M-code: start the spindle
M08 ; M-code: turn on coolant
G00 Z5 ; G-code: rapid retract
M30 ; M-code: end the program
Do I need to memorize all G-codes?
No. Every CNC programmer keeps a reference sheet at their machine. The skill is not memorizing every code number. The skill is understanding what type of operation you need and which code group controls it. With practice the 15 essential codes become automatic. For everything else you bookmark this page and come back when you need it.
What’s Next?
Now that you have the complete G-code reference learn how each code works in practice:

Complete M-Code List: CNC Programming ReferenceJune 25, 2026 · Reference
CNC Machining Tolerances Guide: ISO 2768 Standards and Practical FitsJune 27, 2026 · Reference
CNC Terminology Glossary: 50+ Terms Every Machinist Should KnowJune 26, 2026 · Reference