HAAS CNC Mill G Code Guide
This HAAS CNC mill G code guide is written for engineers and programmers who need to read, edit and debug a program at the machine, not just post it from CAM. We cover how the controller interprets each line, where modal states and offsets bite, and how to tell when a hand edit is safe and when it is not.

In this article
- 1
- 2
- 3
- 4
- 5
- 6
- 7
What G code actually tells a HAAS mill to do
G code is the machine's native instruction set. Your CAM software posts it, but the controller executes it line by line, in order, with no memory of your intent. Every block does one of four things: move an axis, set a state, call a stored cycle, or toggle a machine function such as spindle and coolant. If you can classify a line into one of those four buckets, you can read almost any program.
The critical property is that most of these commands are modal. Once you issue G01, the controller keeps feeding in a straight line until another motion mode appears. Same for G54, G43, G41 and coolant codes. This is why a single missing G00 or G80 can crash a tool 200 mm into a fixture: the last state is still active and the next coordinates are interpreted under it.
Coordinates are not absolute positions in the room. They are positions inside the active work offset, further shifted by tool length compensation and cutter compensation. A program that looks correct on paper can still cut the wrong place because one of those three layers was set wrong. Debug order matters: verify the offset, then the tool length, then the geometry.
On a HAAS control, blocks are processed in the order written, but non-motion commands on the same line execute before the move on that line. This is why G43 H01 on the same block as a Z move is common and safe, while putting a spindle speed change on the same line as a rapid into stock is not.
- 1Motion modesG00 rapid, G01 feed, G02/G03 arcs, G81–G89 cycles
- 2State modesG17 plane, G20/G21 units, G40/G41/G42 comp, G43/G49 length
- 3Offset framesG54–G59 work offsets shift the whole part origin
Work offsets and tool length: where most scrap starts
A work offset defines where the part origin sits in machine travel. On a HAAS mill, G54 through G59 hold six independent frames, and G54 is active at power-up. Every coordinate in your program is measured from that point. If the operator sets G55 but the program calls G54, the part is cut in the wrong location by exactly the distance between the two origins, and no amount of dry running will show it unless you watch the distance-to-go screen.
Tool length compensation is the second layer. G43 applies a stored length offset so the controller knows where the tool tip is relative to the gauge line. Skip it, or call the wrong H number, and the Z depth is wrong by the full tool length. The safe pattern is to call G43 H__ on a Z approach block, with the rapid target well above the stock, then feed down.
A quick sanity check before any first cut: switch the display to distance-to-go, single block, and rapid to 25 mm above the first Z target. Read the remaining distance. If it does not match your setup sheet within a millimeter or two, stop and re-check the offset rather than assuming the display is slow.
For production runs, offset discipline beats programming cleverness. Write the offset number into the setup sheet and into the program comment header. On a 5-axis job we keep the same convention across all 16 simultaneous 5-axis machining centers so a program can move between machines without a second thought.
- 1Set the offset before the toolA wrong G54 makes every tool wrong; a wrong H number makes one tool wrong
- 2Never trust a dry run aloneWatch distance-to-go on the first Z approach
Cutter compensation: powerful, and easy to get wrong
G41 and G42 shift the tool path sideways by the radius stored in the offset table, so you can adjust a finished dimension by editing one number instead of reposting the program. That is the whole value of it. G41 keeps the tool to the left of the direction of travel, G42 to the right, and both are judged in the active plane, which is normally G17 (XY).
The catch is that the controller must be able to compute a lead-in without gouging. Compensation must be activated on a move that is at least as long as the tool radius, and ideally on a straight lead-in perpendicular to the first cut. Activating it on an arc, or on a move shorter than the radius, produces an alarm or, worse, a clipped corner.
Comp also fails on internal corners tighter than the tool radius. No offset value can make a Ø6 mm cutter reach into a 4 mm corner. If the drawing calls for a sharp internal corner, the honest answer is a smaller tool or an EDM pass, not a bigger comp number.
Our rule on the floor: use comp for finishing passes where a dimension may need a tweak, and leave it off for roughing. Roughing wants predictable, full engagement and no surprises. Finishing wants the ability to hold ±0.005 mm without a repost, and that is exactly what comp gives you.
- 1Lead-in lengthAt least one tool radius, straight, before the first cutting move
- 2Internal cornersComp cannot cut a radius smaller than the tool
- 3Rough vs finishNo comp for roughing, comp for finishing
Canned cycles and modal traps on the HAAS control
Drilling cycles store a motion pattern and repeat it at each new XY position until you cancel with G80. G81 drills, G83 pecks with full retract, G73 pecks with a short retract, G84 taps. The parameters live in the cycle call: Z depth, R plane, Q peck increment, F feed. Once called, the cycle is modal and stays armed.
The classic failure is forgetting G80 before the next operation. The tool moves to the next XY position and plunges to the last Z depth. On a part with a tall boss nearby, that is a broken tool and a scrapped part. Get into the habit of ending every drilling section with G80 on its own line, followed by a G00 Z retract.
Peck depth matters more than most programmers expect. In 6061 aluminium, a Q of 3–5 mm per peck clears chips well. In 316 stainless or Ti-6Al-4V, drop to 1–2 mm and use G83 with a full retract, because chip packing is the main cause of drill failure in these materials. Feed per revolution stays consistent; the peck only controls chip evacuation.
Tapping is its own trap. G84 on a HAAS mill needs the correct spindle direction and a feed that matches the thread pitch exactly. On a rigid tap, feed = pitch × spindle speed, and the control handles synchronization. Hand-editing the feed without changing the speed breaks that relationship and strips the thread.
- 1Always close with G80A modal drill cycle will follow your next positioning move
- 2Peck by material3–5 mm in aluminium, 1–2 mm in stainless and titanium
- 3Rigid tap feedFeed equals pitch times spindle speed, no exceptions
When to hand-edit a program and when to repost
Hand edits are fast and they are how you learn the control. They are also how a verified program quietly becomes unverified. The distinction that matters is whether the edit changes geometry or only changes conditions. Changing a feed, a spindle speed, a coolant setting or a peck depth is a condition edit. Changing a coordinate, an offset number or a motion mode is a geometry edit.
Condition edits are low risk and can be made at the machine. Geometry edits should go back through CAM, because the post processor holds relationships you cannot see in the code: stock allowances, entry moves, safe retract heights, tool engagement. Change one coordinate by hand and you may break a lead-in that was sized to avoid a clamp.
There is a middle case worth naming. When a single dimension is running out of tolerance on a finishing pass, cutter compensation is the correct tool, not a coordinate edit. Bump the offset by half the error and rerun the finish pass. That keeps the program and the geometry consistent.
For any part running in production, keep the CAM file and the posted code versioned together. If a machine-side edit saves a setup, note it in the setup sheet and fold it back into CAM before the next run. Otherwise the next operator inherits a program nobody can explain.
- 1Condition editFeed, speed, coolant, peck: safe at the machine
- 2Geometry editCoordinates, offsets, motion modes: repost instead
G code changes shape on 4-axis and 5-axis work
On a 3-axis mill, the part stays still and the tool moves in three linear axes. Add a rotary table, and the controller now has to reconcile a rotating work coordinate system with a linear tool path. G54 stays the origin, but the active plane and the rotary positions change what the coordinates mean, so a program that looks like a 3-axis program can cut in a completely different place.
On simultaneous 5-axis, the post processor outputs a stream of very small linear moves, often 0.05–0.5 mm apart, with the rotary axes interpolated between them. Feed rates are no longer simply mm per minute of tool travel; the control recalculates based on the actual tool tip motion, which is why inverse time feed (G93) appears in some posts and not others.
Cutter compensation behaves differently here too. Applying G41/G42 across a tilted tool axis is unreliable, so most 5-axis finishing is done with CAM-computed offsets and no comp at all. The tolerance then depends on the accuracy of the post and the calibration of the rotary axes, not on an offset table entry.
This is where the machine class shows up in the parts. With a Ø400 mm rotary table and 16 simultaneous 5-axis centers, complex geometry is finished in one setup, which removes the stack-up error of three separate fixtures. The trade-off is that a bad post or a loose rotary calibration is far harder to spot in the code.
- 13-axisCoordinates map directly to tool position
- 24-axisRotary position redefines the active plane
- 35-axisSmall linear moves with interpolated rotary axes
Common HAAS mill codes and what they change
Use this as a reading aid, not a substitute for the machine manual.
| Code | What it does | Modal? | Where it bites |
|---|---|---|---|
| G00 | Rapid positioning move | Yes | Rapid into stock or a clamp |
| G01 | Linear feed move | Yes | Feed stays active into the next block |
| G02 / G03 | Clockwise / counterclockwise arc | Yes | Wrong I, J, K or plane |
| G17 / G18 / G19 | Selects the active plane | Yes | Comp and arcs computed in the wrong plane |
| G40 / G41 / G42 | Cancel / left / right cutter comp | Yes | Short lead-in clips the corner |
| G43 / G49 | Apply / cancel tool length offset | Yes | Wrong H number puts Z at the wrong depth |
| G54–G59 | Select a work offset frame | Yes | Program offset does not match the setup |
| G80 | Cancel a canned cycle | Yes | Left active, next move plunges |
| G81 / G83 | Drill / deep-hole peck drill | Yes | Peck too deep in stainless or titanium |
| G84 | Rigid tapping cycle | Yes | Feed no longer matches pitch times speed |
The short version
If you know the part and the fixture, edit feeds and speeds at the machine. If the geometry is changing, repost from CAM and re-verify the offsets. Never trade a five-minute repost for an unverified coordinate edit on a finished part.
Questions engineers ask about HAAS mill G code
Do I need to know G code if CAM generates everything?
You do not need to write programs by hand, but you need to read them. When a tool breaks, a dimension drifts or a cycle alarms out, the answer is in the code, the offset table or the setup sheet, and usually in that order.
The practical skill is classification: is this line a motion, a state, a cycle or a machine function? Once you can sort lines that way, debugging gets much faster.
Why did my program cut in the wrong place with correct-looking coordinates?
Almost always an offset layer. Check the active work offset against the setup sheet, then the tool length H number, then any cutter compensation value.
A wrong G54 shifts every tool by the same amount. A wrong H number shifts one tool in Z only. That pattern tells you which layer to look at.
Can cutter compensation hold a tight tolerance on a finishing pass?
Yes, and it is the right tool for it. Adjust the offset by half the measured error and rerun the finish pass. No repost needed.
It cannot fix an internal corner tighter than the tool radius, and it should be activated on a straight lead-in at least one radius long.
What peck depth should I use in G83?
In aluminium 6061, 3–5 mm per peck clears chips reliably. In 316 stainless or Ti-6Al-4V, drop to 1–2 mm and keep the full retract.
The peck increment controls chip evacuation, not cutting speed. Feed per revolution stays where your speed and feed calculation put it.
Is hand-editing a proven program ever acceptable?
For conditions, yes: feed, speed, coolant, peck depth. For geometry, no. Coordinate and offset edits break relationships the post processor set up, such as stock allowance and safe retract heights.
If a machine-side edit saves a run, record it in the setup sheet and fold it back into CAM before the next production order.
How does G code differ on a 5-axis HAAS compared with a 3-axis?
The code becomes a dense stream of small linear moves with interpolated rotary positions. Feed rates are recalculated by the control for actual tool tip motion, which is why some posts output inverse time feed.
Cutter compensation is generally not used for simultaneous 5-axis finishing. Accuracy comes from the post processor and rotary calibration instead.
Send us the part and the drawing
We review your geometry, pick the right machine class and quote with a free DFM analysis within 12 hours. Production can start within 24 hours, and every part is inspected before it ships.
12-hour quote100% inspection±0.005 mmNo MOQ