H Code in CNC: Tool Length Offsets (G43) Explained

The H code tells the CNC machine which tool length offset to use when running a program. It works alongside G43 (tool length compensation) to make sure the machine knows exactly how long the current cutting tool is.

Key Takeaways

  • The H code calls up a stored tool length value from the machine’s offset table
  • It is always used together with G43 (or G44) — it doesn’t do anything on its own
  • H1 is paired with tool T1, H2 with T2, and so on — this is the standard convention
  • The H offset value is the measured distance from the spindle nose to the tip of the tool
  • Calling H0 applies zero offset — a common source of crashes for beginners
H Code – At A Glance
FunctionHeight Offset (Tool Length Offset)
Used WithG43, G44
Offset TypeLinear (Z-axis)
Where StoredTool Offset Table
Typical PairingH1 = Tool 1, H2 = Tool 2
Cancelled ByG49

What Does the H Code Do?

Every cutting tool has a different length. A short drill and a long end mill sitting in the same spindle reach different depths for the same Z move. Without accounting for this, your program would cut at the wrong depth — or crash the tool into the part.

The H code solves this. It pulls a length value from the tool offset table and gives it to the machine so Z moves are adjusted correctly.

The H code is always paired with G43 (positive tool length compensation). You will see it written like this:

G43 H1 Z2.0

This tells the machine: apply the length stored in offset #1 to the Z-axis position.

illustration of a cnc cutting tool that shows what an H offset is

What is tool length compensation?

Tool length compensation (TLC) is how the CNC machine accounts for differences in tool length. When you put a new tool in the spindle, it almost never sits at the exact same position as the last one. Even 0.010″ of difference can matter when you’re holding tight tolerances.

Instead of rewriting the program every time you swap tools, you measure each tool’s length and store it in the offset table. The H code calls that stored value at runtime.

G43 is the standard for positive offset — the machine adds the offset value to your Z positions. G44 (negative offset) exists but is rarely used in modern CNC programming. Stick with G43 unless you have a specific reason not to.

mach 3 tool offset table
Tool offset table

How to Set an H Offset at the Machine

Setting the H offset is a physical setup step — it happens at the machine before running the program.

The most common method is touching off each tool:

  1. Load the tool into the spindle
  2. Jog the Z-axis down until the tool tip just touches a reference surface (often the top of the part or a known reference block)
  3. Note the Z machine coordinate
  4. Enter that value into the H offset register for that tool

Some shops use a tool length measuring device (tool presetter) that reads the length automatically. Either way, the value ends up in the offset table where the H code can call it.

COMMON MISTAKE – Not adding the height of your reference block

Why it matters: If you touch off your tool to the top of a 2.000″ reference block and enter the raw machine coordinate without adding 2.000″, your offset is off by the full height of the block. The tool will cut 2 inches deeper than intended — likely a crash or a scrapped part.

Always add the block height to whatever Z coordinate the machine shows during touch-off.

H offset vs D offset

H and D offsets both live in the tool offset table, but they store different things.

The H offset stores the length of the tool (the Z-axis dimension). The D offset stores the diameter (used for cutter radius compensation with G41/G42).

A typical tool in a program uses both:

T01 M06           (Call tool 1)
G43 H1 Z2.0       (Apply H1 for length compensation)
G41 D1 X1.0 F20.0 (Apply D1 for diameter compensation)
illustration of a cnc cutting tool that shows what an D offset is
illustration of a cnc cutting tool that shows what an H offset is

H Offset Numbering

The standard convention: match your H number to your tool number. Tool 1 uses H1, tool 2 uses H2, and so on. This keeps programs readable and easy to troubleshoot.

On most modern CNC controls, H and D offsets are stored separately so there’s no conflict using H1 and D1 for the same tool. Older machines sometimes share the offset registers between H and D values. If you run into that situation, a common workaround is to start one set of offsets at a higher number — for example, use H1–H20 for length offsets and D21–D40 for diameter offsets.

If you’re working on a newer machine, follow the simple rule: T1 = H1 = D1.

H Code Program Example

Here’s a short program showing how the H code fits into a typical milling operation:

T01 M06              (Tool change to tool 1)
G00 X4.0 Y5.0        (Rapid to XY position)
G43 H1 Z2.0          (Turn on tool length comp with H1, rapid to Z2.0)
G01 Z-0.5 F20.0      (Feed into cut)
G00 Z2.0             (Retract)
G49                  (Cancel tool length compensation)

The G43 H1 line is where the H code does its work. The machine reads the value stored in offset register #1 and uses it to adjust all Z positions from that point forward until G49 cancels it.

COMMON MISTAKE – Not cancelling G43 with G49 before a tool change

Why it matters: Some controls carry the previous H offset forward into the next tool. This can cause the next tool to cut at the wrong depth.

Always cancel with G49 — or make cancellation part of your tool change routine.

FAQS

What does the H code do in CNC?

The H code calls a tool length offset value from the machine’s offset table. It is used with G43 to compensate for differences in tool length so the machine cuts at the correct Z depth.

What is the difference between H offset and D offset?

The H offset stores the length of the tool (Z-axis). The D offset stores the diameter. H is used with G43/G44 for length compensation; D is used with G41/G42 for cutter radius compensation.

What happens if I use H0?

H0 applies zero tool length compensation. The machine ignores any stored offset and moves to the raw Z coordinates in your program. This is a common cause of tool crashes for beginners.

Does the H number have to match the tool number?

It doesn’t have to, but it’s the standard convention. Using T1 with H1, T2 with H2, and so on makes programs easier to read and troubleshoot. Deviation from this pattern should always be intentional and documented.