What are Work Offsets [G54-G59 Codes Explained]

a graphic of a cnc machine with text that says learn g code today G54-G59 work offsets




Work offset


Modal - stays on until changed


The machine will interpret all location values as distances from the work offset

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 currently used in the CNC program.

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 changed with a new 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.

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.

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

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

counterbore on metal part
A hole with a counterbore

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 know exactly what mode the machine is.

At times, CNC programs might be run out of sequence. If the program didn’t call out the necessary modes at the start of each section, then bad things can happen when the machine is not in the correct mode.

In our example above with the holes and counterbores, imagine you check the holes and find out that they came out undersize.

Time to make them bigger.

To do this you decide to only run the hole section of the code. 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 there is the possibility that another work offset command is currently active. Instead of using the correct part zero location, the machine will be thinking the part is located somewhere else. 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 machine needs to know where the part is located.

What to think about when using a G54 code

When you use the G54 code, you just need to know which work offset you are working with. Because the command is modal, one and only one will be active.

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.

G54 vs G55-G59

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

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

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 machining multiple parts at once easier.

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

G54 code examples

Imagine we wanted to drill a hole 2 inches up and 2 inches over from the zero location (shown in red) in each of the parts above.

Our code would read:

G54                                (Work offset 1)

G01 X2.0 Y2.0 F10.0     (Move to hole drill position and set feed rate)

G81 R0.1 Z-0.5 F2.0       (Hole drilling cycle)

G55                                (Work offset 2)

G01 X2.0 Y2.0 F10.0     (Move to hole drill position and set feed rate)

G81 R0.1 Z-0.5 F2.0       (Hole drilling cycle)

G56                                (Work offset 3)

G01 X2.0 Y2.0 F10.0     (Move to hole drill position and set feed rate)

G81 R0.1 Z-0.5 F2.0       (Hole drilling cycle)

Rinse and repeat for every work offset (part) needed.

This is very simplified but you can see that we set the work offset, so the machine knows where the part is located.

We then run the same two lines over and over to drill the hole. We could put these in a subprogram to use repeatedly, but we wrote it all out to make it easier to understand.

If the same piece of code was written as a subprogram it would look like:

G54                                (Work offset 1)

M98 P1001                    (Run hole drilling subprogram)

G55                                (Work offset 2)

M98 P1001                    (Run hole drilling subprogram)

G56                                (Work offset 3)

M98 P1001                    (Run hole drilling subprogram)

O1001                            (Drilling subprogram)

G01 X2.0 Y2.0 F10.0     (Move to hole drill position and set feed rate)

G81 R0.1 Z-0.5 F2.0       (Hole drilling cycle)

M99                                 (End subprogram)

This is a really small program, but you could imagine that you could save a lot of coding if you use subprograms and the G54-G59 work offsets.

If instead of just drilling a hole, you machine the outside and then drilled and counterbored 20 holes then the subprogram would be large but the main program would be small.

You essentially have one subprogram for machining the part. Then in your main program you switch between the work offset locations and machine the same subprogram.

Writing with subprograms has the advantage of making the program easier to follow along with. This makes troubleshooting easier as well. Whenever possible make your programs as simple you can. It will help you and/or any one else who needs to use the program such as setup personnel or operators.

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

See here if you need more info about G10 codes.

Want to learn more about G Code for your CNC?

Leave a Comment