H CNC Code Explained: An Easy Intro for Beginners [Height Offsets]

What does the H CNC code do?

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 the G43 or G44 codes are used in the program.

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

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 the difference in tools, 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 of tool length compensation 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.

Learn CNC Programming – It’s Easier Than You Think!

Learning G Code doesn’t have to be difficult…

If you know what to focus on.

Join our simple, easy-to-follow course, “G Code Made Easy: CNC Programming for Beginners“. We walk you through all the important codes – with simple explanations and real-world examples.

Want to become a super-skilled CNC programmer? Join now to take the shortcut to becoming a G Code Master today!

Make Learning G Code Easy

H offset vs D offset

D offsets store the diameter of the cutting tool. 

D offsets are called up using the D code.

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

H offsets store the length of the cutting tool and are called up using the H code.

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

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 offset numbering. 

Unfortunately, some machines won’t allow you to set a diameter (D) offset 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.

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 will 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