Top 25 Essential G-Codes for CNC Machining: Explained with Real-World Examples
Whether you’re a CNC operator, programmer, or student, mastering essential G-codes is the foundation of reliable, efficient machining.
This guide explains the 25 most commonly used G-codes, grouped by function, with clear examples and professional tips.
You can apply these codes in Fanuc, Haas, Siemens, Heidenhain-based machines with minor syntax changes.
🧭 1. Movement G-Codes
These control toolpath motion directly.
| Code | Function | Description |
|---|---|---|
| G00 | Rapid Positioning | Fast non-cutting move to position |
| G01 | Linear Interpolation | Straight-line feed move |
| G02 | Clockwise Arc | CW circular path |
| G03 | Counter-Clockwise Arc | CCW circular path |
🔍 Example:
G00 X0 Y0 (Rapid to start point)
G01 X50 Y0 F150 (Linear feed to right)
G02 X50 Y50 R25 (CW arc to top)
G03 X0 Y50 R25 (CCW arc to left)
💡 Tip: Always set feedrate (F) before G01, G02, G03 to avoid unpredictable machine behavior.
📐 2. Plane Selection & Coordinate Systems
| Code | Function | Description |
|---|---|---|
| G17 | XY Plane | Default for milling |
| G18 | ZX Plane | Used for lathe arcs |
| G19 | YZ Plane | Vertical arcs in YZ |
| G54–G59 | Work Offsets | Up to 6 separate work origins |
🔍 Example:
G17 G54 (XY plane, first work coordinate)
G00 X0 Y0 Z5
G01 Z-2 F100
💡 Tip: Use G55–G59 for setting up multi-vise or pallet jobs without modifying main code.
🔃 3. Canned Cycles (Drilling, Tapping, etc.)
| Code | Function | Description |
|---|---|---|
| G81 | Drilling Cycle | Basic peck-free drill cycle |
| G83 | Peck Drilling | For deeper holes and chip break |
| G84 | Tapping (RH) | Rigid or floating tapping cycle |
| G85 | Boring (No Dwell) | For boring without pause |
🔍 Example:
G98 G83 X10 Y10 Z-15 R2 Q3 F100
💡 Tip: G83 is ideal for deep holes (>3×D). Use
Qfor peck depth andRfor retract height.
⚙️ 4. Tool Control & Compensation
| Code | Function | Description |
|---|---|---|
| G40 | Cancel Cutter Compensation | Disables G41/G42 |
| G41 | Cutter Comp Left | Compensates to left of path |
| G42 | Cutter Comp Right | Compensates to right of path |
| G43 | Tool Length Comp + | Activates tool length offset |
🔍 Example:
G43 H1 Z100 (Apply tool length from offset H1)
G01 Z0 F200
💡 Tip: Always pair G43 with the correct H offset or you risk crashing into the part or vise.
🔁 5. Program Flow & Repeats
| Code | Function | Description |
|---|---|---|
| G70 | Finish Cycle | Repeat G71 rough pass |
| G71 | Rough Turning | Lathe rough cut cycle |
| G90 | Absolute Mode | All positions from part zero |
| G91 | Incremental Mode | Moves relative to current point |
| G98 | Return to Initial | Canned cycle return mode |
| G99 | Return to R-Plane | Preferred in deep pocket drilling |
🛑 6. Safety & Initialization Codes
| Code | Function | Description |
|---|---|---|
| G20 | Inch Mode | All distances in inches |
| G21 | Metric Mode | All distances in millimeters |
| G28 | Return to Reference | Sends axes to machine zero |
| G94 | Feed per Minute | F value = mm/min or in/min |
🔍 Startup Block Example:
G21 G17 G90 G40 G80 G94
💡 Tip: Place this line at the start of every program to eliminate unpredictable states from previous jobs.
🧠 Summary Table
| Category | G-Codes |
|---|---|
| Movement | G00, G01, G02, G03 |
| Plane & Coordinates | G17–G19, G54–G59 |
| Drilling Cycles | G81, G83, G84, G85 |
| Tool Compensation | G40, G41, G42, G43 |
| Program Control | G70, G71, G90, G91, G98, G99 |
| Initialization | G20, G21, G28, G94 |
🎯 Final Thoughts
Understanding these 25 G-codes gives you the toolbox you need to program 90% of CNC parts — from basic holes to complex contours.
But don’t stop here — mastering these codes also means learning when, why, and how to apply them together in real machining contexts.
Leave a comment