D CNC Code Explained: An Easy Intro for Beginners [Diameter Offset]

What does the D CNC code do?

The D code is used to choose the D offset that is used when cutter compensation is turned on.

The D offset value is a number stored in the CNC machine controls that tells the CNC the size of the cutting tool. 

Once the machine knows the size of the cutter it can adjust how it runs the program based on that size.

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

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

What is cutter compensation?

Cutter compensation is a CNC mode that allows the CNC controller to adjust for the size (diameter) of the cutting tool. 

Setting the size of the cutting tool allows you to use the same program with multiple different cutting tools.

Turning cutter compensation on tells the machine to shift the cutting tool either left with G41 or right with G42

The shift is half of the diameter of cutting tool, otherwise known as the radius.

illustration that compares a circles radius and diameter
The circle center would be the center of your cutter

Visualizing which way the machine will shift can be a little tricky. The shift happens as if you are looking towards the direction that the cutter is moving.

The images below show how the CNC will move when cutter compensation is off (canceled) with G40 and when it is on using either G41 (cutter compensation left) or G42 (cutter compensation right).

Study the images below to understand how cutter compensation adjusts the path of your cutting tool.

illustration that shows how a CNC will act when there is no cutter compensation mode active
illustration that shows how a CNC will act when using cutter compensation left with the G41 code
illustration that shows how a CNC will act when using cutter compensation right with the G42 code

What are the benefits of using cutter compensation with a D offset?

The benefit of using cutter compensation and D offsets is that adjustments can easily be made to the part being machined without the need for rewriting the whole program.

For instance, if you were to machine your part and find that the part was larger than planned then the D offset could be changed to adjust the size of the part.

D offsets get changed for a variety of reasons. 

The part could finish at an unexpected size, the cutting tool could wear changing the size or the cutting tool may need to be changed. 

All of these examples could be fixed through changing the D offset stored in the controller.

Without the use of a D offset, the CNC program would need to be rewritten to make these adjustments. This would be more difficult and require a lot more time.

Can you have more than one D offset?

Yes, you can have more than one D offset but you cannot have more than one D offset active at a time.

This means you can have multiple D offsets stored in your machine controller, one for each of the tools in your machine. 

However, only one can be on at any time.

D offsets are stored in the offset library of your CNC machine.

Generally, the D offset number will be the same as the tool number it is associated with.

Offset Library
Tool offset table with D offsets listed on the right side

Where are D offset values stored?

Most CNC machines allow the cutting tool information to be stored in table form. This tool library is called the tool offset table.

mach 3 tool offset table
Tool offset table

The tool offset table, sometimes called tool table or offset library, is simply a table of values that list the characteristics of the cutting tool, such as the diameter and length of the tool.

Tool offset tables vary from machine to machine. 

Some will allow you to store the length and diameter offsets together with a single tool. Some will require separate entries for diameter and tool length offsets.

D offset numbering

The D offset for tool number 01 will also be 01. This is best practice.

T01 = tool number 1

D01 = D offset number 1

The D offset number does not have to be the same as the tool number. Sometimes this won’t even be possible depending on the machine.

When possible, it is a great idea to number the offsets the same as the tool they will be assigned to.

D offset vs H offset

D offsets store the diameter of the cutting tool. 

H offsets store the length of the cutting tool.

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

Similar to how the G41 and G42 codes are used to turn on cutter compensation with a D offset, the G43 code is used to turn on tool length compensation using an H offset.

Both compensation modes also have cancel commands to turn them off. The G40 code turns off cutter compensation using D offsets and the G49 code turns off tool length compensation using H offsets.

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.

Want to learn more about CNC G Code?

Leave a Comment