Quick Guide to the H CNC Code [Height Offsets]

a graphic of a cnc machine with text that says learn g code today h height offset

The H CNC code tells the machine to which height (H) offset to use with the current cutting tool.

The value of the H offset is the distance between the end of the spindle and the end of the cutting tool.

The H offset/code is used when tool length compensation with either G43 or G44 is used in the program.

Want to learn more about CNC G Code?

What is tool length compensation?

Every time a new tool is placed in the CNC spindle, the length of the tool is different. This is often the case even when putting the same tool back into the spindle.

Depending on the types of tolerances you are working with, the tool sitting in the spindle 0.001” higher or lower can create a part that is out of spec.

To account for this an H offset value can be assigned to each cutting tool.

Setting up your machine and program in this way allows you to use the same program with a variety of different tools.

You wouldn’t want to have to rewrite your program just because you got a new end mill and it is 0.010” shorter than the last one. Tool length compensation lets you account for this type of change in your cutting tool.

There are two types of tool length compensation, positive compensation with G43 and negative compensation with G44.

G43 is the most common type and used in the vast majority of CNC programs. If you are just learning what tool length compensation is, then ignore G44 for now. You aren’t going to be using it.

What are the benefits of using an H offset?

H offsets are useful for a variety of reasons:

  • Programs are more flexible. They don’t need to be rewritten every time a new tool needs to be used or changed.

Saves time. Multiple H offsets can be set and the program can run uninterrupted without the need to set new Z axis zero locations.

H offset numbering and tools

Generally, the H code number is the same as the tool number in the Tool Offset Library.

For example, when using tool #1 (T1), it is advised to pair it with H offset #1 (H1). The same can be said for tool #2 and H offset #2 and so on.

Using a pattern like this makes it easier for the operator or programmer to understand.

Machines vary with how they handle offsets. Unfortunately, some machines won’t allow you to set a diameter (D) and height (H) offset for the same offset number.

If you are unable to use the H1 offset with tool #1 then try to create your own logical pattern. Usually this means starting the numbering of one type of offset at a higher number such as H21 or H51. This is more of an issue with older CNCs.

H offset vs D offset

D offsets store the diameter of the cutting tool. H offsets store the length of the cutter.

Both offset types allow more flexibility when running the program and when switching between various cutting tools.

Both offset types are stored in the tool offset table.

mach 3 tool offset table
Tool offset table

How to use the H code in a program?

T01 M06  

G00 X4.0 Y5.0

G43 H1 Z2.0

G01 Z-3.0 F100

In this example, the machine will switch to tool #1.

There will then be a rapid movement to the XY location of (4.0, 5.0) or X=4.0 and Y=5.0.

Tool length compensation is then turned on with the G43 command using the H1 height offset. The machine will then move to a Z location of 2.0. This be a rapid movement as well because the movement mode has not been changed since the G00 rapid travel command was used.

The last line sets the CNC to straight line movement (linear interpolation) with a feed rate of 100. The machine will move to a Z location of -3.0.

Want to learn more about CNC G Code?

Leave a Comment