G-Code Fundamentals
G-codes tell the machine what kind of motion to perform. This page covers the four core motion codes — G00, G01, G02, G03 — their syntax, modal behavior, and the safety rules that prevent crashes.
Concept
G00 is rapid positioning: the machine moves as fast as possible to a target position. It is not a cutting move — no F command is used. G01 is linear interpolation: the machine moves in a straight line at a specified feed rate while cutting. G02 and G03 are circular interpolation — clockwise and counterclockwise arcs, covered in detail on the circular interpolation page.
G00 and G01 are modal: once you set G01, every subsequent motion block stays in G01 until another motion code replaces it. You do not need to write G01 on every line — it persists.
Why It Matters
G00 moves at rapid speed (often 15–40 m/min). If the tool is not above the stock when you rapid in X/Y, it crashes into the vise or part. The #1 cause of beginner crashes is unsafe G00 motion. Always make sure Z is at a clearance height before rapid in X/Y.
The G00 path depends on the controller and machine. On many machining centers each axis accelerates independently at its own rapid rate, so the tool does not follow a straight diagonal line; the actual path is determined by how the controller blends rapid motion. This matters because a straight line might clear a fixture while the actual rapid path does not. Always check the controller manual for how G00 is interpolated on your machine, and verify the rapid path in simulation or at low override before relying on it.
How It Works
G00 — Rapid Positioning
G00 X50. Y30.
Moves the tool to X50 Y30 at maximum rapid speed. No F command. Used only for positioning between cuts — never for cutting. On many machines, axes move independently rather than in a straight diagonal, so visualize the actual path.
G01 — Linear Feed
G01 X50. Y30. F200.
Moves in a straight line at feed rate 200 mm/min. The F is modal — once set, subsequent G01 lines inherit it. The first G01 after a G00 must specify F.
G02 / G03 — Circular Interpolation
Cut arcs: G02 clockwise, G03 counterclockwise. Requires I/J or R to define the arc. See Circular Interpolation for full detail.
Safe Approach Pattern
G00 X0 Y0 (rapid XY to above target, at safe Z)
G00 Z5. (rapid Z to 5 mm clearance)
G01 Z-2. F100. (feed down to cut depth)
G01 X50. F300. (feed cut)
G00 Z50. (retract up BEFORE next XY)
The critical rule: Z goes up before XY moves. Never rapid sideways at cut depth.
Example: Safe Approach and Cut
This is a motion fragment, not a complete setup program. Assume G21, G17, G90 and G94 are active; the intended work offset and tool-length compensation are verified; and the spindle and required coolant are already running. The selected Ø10 mm center-cutting end mill is suitable for the illustrated axial entry. Z0 is the stock top. Z50 clears the stock, clamps and holder envelope along the transfer route; the approach and cutting locations are clear of clamps. The speeds and feeds are teaching assumptions, not tooling recommendations.
On a Haas mill with a Ø10 end mill, cutting a straight groove 2 mm deep into aluminum. Starting position is X0 Y0 Z50 (above the part corner):
G00 X20. Y15. (1: rapid XY to above cut start, at Z50 safe)
G00 Z2. (2: rapid down to 2mm clearance above surface)
G01 Z-2. F100. (3: feed down to cut depth at 100 mm/min)
G01 X60. F300. (4: feed cut along X at 300 mm/min)
G00 Z50. (5: retract up to safe Z BEFORE any XY move)
Step 1 is rapid — the tool is at Z50, well above the stock, so XY motion is safe. Step 2 drops to Z2. Step 3 switches to feed (G01) and enters the cut. Step 4 does the cutting. Step 5 retracts in Z first — only after Z is at 50 is it safe to rapid in XY again. This order (up, over, down, cut, up) prevents the #1 crash.
Common Mistakes
- Rapid XY at cut height — always retract Z to clearance before moving in X/Y. This is the #1 crash cause.
- Forgetting F on the first G01 — the feed may default to a dangerous value. Always specify F on the first feed move.
- Using G00 for cutting — G00 is positioning only; it moves too fast and does not maintain a controlled cut.
- Assuming G00 is straight-line — axes move independently; the path may not be a straight diagonal and can hit obstacles.
- Forgetting that G01 persists — once G01 is active, every motion block stays in feed mode until G00, G02, or G03 replaces it. You do not need to repeat G01 on every line.
Practice
1. When is G00 safe vs unsafe?
Show answer
Safe: tool is above the clearance plane, clear of all fixtures. Unsafe: tool is at cut depth or near the stock. Always retract Z before rapid XY.
2. Distance 40 mm at F200. Cutting time?
Show answer
40/200 = 0.2 minutes = 12 seconds.
3. Why is G01 modal important?
Show answer
Once G01 is set, you do not need to repeat it on every line. It persists until G00, G02, or G03 replaces it. This keeps programs shorter.
Sources
- Haas G00 Rapid Positioning — supports rapid motion behavior.
- Haas G01 Linear Interpolation — supports feed motion and F command rules.
- Program examples and speeds/feeds are classroom teaching assumptions; verify against tooling catalogs and machine documentation.