G54-G59 CNC Codes Explained: An Easy Intro for Beginners [Work Offsets]

What does a G54 code do?

The G54 command tells the CNC machine where your part is located.

To put it differently, the G54 code sets the work offset zero location to be used currently in your CNC program.

On most CNC machines, the G54 through G59 codes are for selecting these work offsets or work coordinate systems. G54 is the first code in this group and the most frequently used work offset G code.

These work offset codes (G54-G59) are each matched to coordinate locations which have been set in the CNC machine’s offset library.

CNC program zero list showing XYZ coordinate locations
Work offset locations

Selecting a work offset code tells the CNC machine which work coordinate system to use. The coordinate locations tell the machine where the zero location is. This is the location where the X, Y, and/or Z coordinate values = zero.

G54 is a modal command

Once the G54 work offset code is used, all sizes and locations in the program will be relative to the zero location of the part until the offset is switched to a different work offset code such as G55 or G56.

This type of G code is called a modal command.

Modal commands remain in effect until they are canceled. This is true even if you restart your program.

Until you cancel the command or change it, the modal command G54 will stay in effect.

Obviously, this can cause trouble if you aren’t paying attention.

For this reason, most CNC programs will be created with start-up or safety commands. The safety commands make sure that the machine is always in the correct modes and this includes having the correct work offset chosen.

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

G54 vs G55-G59

All of the CNC codes from G54 to G59 act the same. They are all work offsets.

Everything in this article that applies to the G54 command also applies to all of the other work offsets including G55-G59.

Work offsets work like presets on your radio, except you store a location instead of a radio frequency. You can then call it up quickly and switch between them as needed.

This makes operations such as referencing different sides of a part or machining multiple parts at once easier.

two work offsets being used on the same part
Two work offsets being used to drill holes on a single part

Each of these commands is modal so they will stay on until turned off or changed.

The picture below shows how multiple work offsets can be set in a CNC and how they compare to the machine zero location.

visual to show cnc work offsets G54-G59 with the zero locations shown

When to use a G54 code

A G54 code can be found at any point within the program but the most likely location is at the start of the program or at the start of a new section of code.

Example time!

Imagine you have a part that you want to drill holes in and then counterbore the same holes.

counterbore on metal part
A hole with a counterbore

In the program there will be a section of code for drilling the holes and a section of code for counterboring them.

Even though those operations both use the G54 offset, the G54 command would be given at the start of each of these sections of code.

This allows the programmer or operator to make sure the correct work offset mode is active.

Our imaginary example program is shown below.

an example of how modal cnc modal work offsets work

At times, CNC programs might be run out of sequence. 

If the program didn’t call out the necessary modes (in this case, the correct work offset) at the start of each section, then bad things can happen when the machine starts to perform an operation based off a different work offset/location.

In our example above with the holes and counterbores, imagine you finish the L&W roughing portion of the code and you check the holes only to find out they are undersize.

Time to make them bigger.

To do this you decide to only run the hole section of the code. This saves time compared to running the whole program right?

If you haven’t called out the G54 command in the hole section of the code, then the machine will continue using the G55 work offset that was used for the L&W roughing.

This can definitely end up with a crashed machine and/or damaged parts.

For this reason, safety lines are included in the CNC program at the start of each section.

The CNC machine needs to have the necessary modes set before any machining operation and the correct work offset is one of those modes.

Which work offset is the most commonly used?

The most common CNC work offset is the first one, G54.

Other work offsets are G55-G59.

Some machines may have more, but G54-G59 are the ones found on almost all CNC machines.

CNC codes that are similar to G54

G53 – Machine coordinate system

G53 is used to send the machine to a location based on the machine zero.

Typically, this is the home/return position for the machine.

Unlike G54, the G53 command is not modal. The G53 code only affects the line it is used on. It is a one-time use code.

This is a handy code to use, but not all machines have it. Keep in mind that older machines, and even some of the newer ones might think the code is something else.

Not all CNC codes are universal across the different manufacturers .

You can expect that G54 will be the same on every machine, but I can’t say the same for G53.

G28 – Machine coordinate system

The G28 code is used to send the machine to a location and then to the machines zero location in one or more of axes.

How does G10 affect G54 and other work offsets

A G10 code is used to change an offset value.

The format for using G10 looks like this:

G10 L2 P1 X1.5 Y2.3 Z 3.0

The L code is for the offset type.

The P code is the offset number.

G10 codes are not something for beginners. Also, the code format isn’t the same across all CNC controls. It is important to know how your machine will react to a G10 codes. Consult your manual.

Want to learn more about G Code for your CNC?

Leave a Comment