CNC G-code Guide

What Is G28 in CNC? Reference Return Explained

G28 is a reference-return command used across CNC controls. How it actually moves the tool depends on the controller, the coordinate mode, and the axes you program — so the safe way to use it is to understand the path before you run it.

Haas-style reference return (illustrative)

; switch to incremental, zero-distance intermediate
G91 G28 Z0.
G90 ; restore absolute mode

At a glance

Command typeReference return (non-modal on Haas)
Coordinates affectedSpecified axes only
Modes in playG90 / G91
Related codesG29, G30, G53
Main riskUnverified path
Required before runManual + simulation
Quick answer

G28 is a CNC reference-return command that moves the specified axes to a machine reference position. Depending on the controller and the programmed coordinates, the motion may include an intermediate position before the reference return. G28 does not automatically guarantee a collision-free path — its behavior must be verified against the machine's programming manual and the actual setup.

What Does G28 Do in CNC Programming?

G28 is used to send one or more axes to a machine reference position — the position defined by the machine configuration, not a fixed point you assume from the part. To read a G28 move correctly, keep four ideas separate:

  • Machine reference position — set by the machine builder and the axis configuration. It is not a fixed corner you can infer from the part model; the location is machine-defined.
  • Machine coordinate system — the coordinate frame the control uses to describe machine axis positions.
  • Work coordinate system — for example G54, the frame your program uses to describe the part. A reference return is a motion, not a command that clears or resets stored work offsets to zero.
  • Intermediate point — on some controllers and with some programming, the axis passes through an intermediate position before reaching the reference position.

Calling G28 is a positioning action. It is not a precision result by itself, and it does not by itself prove a part will hold a specific tolerance.

How G28 Moves the Machine

The actual path depends on two things: which axes you address, and whether an intermediate move applies. When no axis is addressed, the control may return the relevant axes directly. When axes are addressed, those axes move toward the reference position, and on some controls the addressed coordinates act as an intermediate point before the return. The diagram below shows the relationships; the real motion must be confirmed in the machine manual.

Machine travel envelope A · current tool B · intermediate (when used) R · machine reference C · G53 target (machine coords) Dashed blue: G28 path (A → B → R). Dotted purple: G53 positions to a machine-coordinate target C.
Schematic only. The intermediate point and the reference position are controller- and machine-dependent; verify against the programming manual and the actual setup before running.

G28 Examples With G90 and G91

The examples below are written in a Haas-style milling convention and are shown to explain the idea. They are not a program you can copy to every controller, machine axis layout, or fixture. Always check the machine manual and verify the motion by simulation or single-block run.

Recommended pattern — incremental zero-distance intermediate, then restore absolute mode:

; select incremental mode G91 G28 Z0. ; Z returns via a zero-distance intermediate G90 ; restore absolute mode for following blocks

In this Haas-style reading, G91 makes the intermediate point zero-distance, so the Z axis returns to the reference position without first translating to a non-zero location in the current work coordinate system. Restoring G90 matters: if the program stays in incremental mode, the next blocks can be interpreted incorrectly.

Risk pattern — absolute coordinates as the intermediate:

G28 G90 X0 Y0 Z0 ; in Haas milling semantics, may move to work-coord X0 Y0 Z0 first

With a work origin placed at or near the part or fixture, that first move toward X0 Y0 Z0 can travel through the part, clamps, or other obstacles before the return begins. This is exactly why the path — not just the endpoint — has to be checked.

Does G28 Work the Same on Every CNC Controller?

No single sentence covers every control. The table below states what the referenced documentation describes, and where it stops short of a universal claim.

Control / systemDocumented behaviorHow this page treats it
Haas millWith no axis address it can return the applicable axes to machine zero; addressing axes can involve an intermediate move, and G90/G91 change the motion meaning.Used for the G90/G91 examples above.
Haas latheSupports X/Z and the U/W incremental addresses; G28 U0 W0 returns to machine zero in that lathe semantics.Lathe syntax is treated separately from mill syntax.
LinuxCNCG28 uses predefined reference-position parameters; an addressed move can also travel between a specified location and the stored position.Shown as different from some Haas forms — not equated.
FANUCG28 returns to the reference position; compensation and parameter details vary by version and machine builder.No single compensation rule is applied across all FANUC machines.
Source discipline: statements here follow controller and system documentation (Haas milling and lathe definitions, LinuxCNC G28 documentation, FANUC programming manuals). Where a behavior depends on machine builder configuration, the page asks you to verify rather than asserts a universal rule.

G28 vs. G29, G30, and G53

These codes are related but not interchangeable. The most common confusion is reading G28 as automatic collision avoidance and G53 as a one-command return to machine zero.

CodePrimary purposeShould not be read as
G28Return the addressed axes to the machine-defined reference position.An automatic obstacle-avoiding path.
G29On supported controls, return from the reference position using the related intermediate logic.An identical return path on every system.
G30Return to a second reference position where the control supports it.The automatic tool-change position by definition.
G53For that block, position using the machine coordinate system; you still specify the target coordinates.A zero-address command that returns to machine origin on its own.

For more on the wider G-code set, see other CNC G-code commands and, when you first meet CNC, what CNC machining means.

Common G28 Programming Mistakes

MistakeWhy it goes wrongWhat to do instead
Wrong intermediate in absolute modeThe machine may first move to the addressed work-coordinate location.State the coordinate meaning clearly and confirm the actual intermediate path.
Assuming G28 avoids collisionsThe axis path can still cross the fixture, part, or structure.Check the whole path and the motion envelope, not only the destination.
Forgetting to restore G90Following blocks may keep being read in incremental mode.Restore the position mode in the example and verify the next block.
Treating all-axis return as default-safeSimultaneous motion can interfere with the part, clamps, or machine structure.Set the axis order from the machine structure and the operation's purpose.
Assuming G28 clears or keeps all compensationCompensation is decided by the controller, parameters, and builder configuration.Check the specific controller's tool length and radius compensation notes.
Calling G28 after an alarm or stopThe tool, workpiece, or axis state may not match the program's assumption.Follow the manufacturer's recovery procedure; do not use G28 as emergency recovery.

On tool length and radius offsets specifically, see the CNC H-code and tool length offsets guide.

G28 Safety Checklist Before Running a Program

  1. Check the manual. Read the G28 section for your exact controller and machine builder; do not assume another machine's behavior.
  2. Confirm the position mode. Know whether the move is interpreted in G90 (absolute) or G91 (incremental) and what the addressed coordinates mean.
  3. Simulate first. Run the program in simulation or single-block mode and watch the intermediate path, not only the endpoint.
  4. Confirm the machine travel. Verify the tool, holder, spindle nose, fixture, and rotary axes have clearance through the whole move.
  5. Verify compensation state. Check what happens to tool length and radius compensation on your control around the return.
  6. Do not use G28 as recovery. After an alarm, interruption, or collision, assess the actual state and follow the defined recovery procedure before any programmed return.

Frequently Asked Questions

What does G28 mean in CNC?
G28 is a reference-return command. It moves the specified axes to a machine reference position. On many controls the move can pass through an intermediate position before the reference return. The exact path depends on the controller and the coordinates you program, so it must be read against the machine's own programming manual.
Is G28 modal or non-modal?
On Haas controls G28 belongs to Group 00, which means it is non-modal: it acts only on the blocks where it is programmed, not as a sustained motion mode. Other controllers organise codes differently, so always confirm the grouping in the relevant programming manual before assuming behavior.
Why is G91 commonly used with G28?
In an incremental step, a zero-distance intermediate point (for example G91 G28 Z0.) lets the axis return to the reference position without first translating to a non-zero intermediate location in the current coordinate system. This is a common Haas-style convenience, not a rule that applies identically to every controller, machine axis configuration, or fixture layout.
Does G28 cancel G43 tool length compensation?
Tool length compensation, radius compensation, and modal state are handled by the controller, the machine parameters, and the manufacturer's configuration. One simple rule cannot cover every model. Check the specific controller and machine builder documentation for what happens to compensation around a reference return.
What is the difference between G28 and G53?
G28 performs a reference-position return, and on some setups routes through an intermediate point. G53 is a non-modal command that positions the tool using the machine coordinate system for that block; you must still specify the target coordinates, and it is not the same as an automatic return to machine zero.
Does G28 reset G54?
G28 is a motion command to a reference position. It is not the same as clearing stored work offsets such as G54. Whether any offset state changes depends on the controller and machine configuration, so confirm the actual behavior in the programming manual rather than assuming a reset.
Can G28 be used after an emergency stop or alarm?
No. After an alarm, interruption, or collision the tool, workpiece, and axis state may not be what the program assumes. Do not treat G28 as a generic recovery command. Assess the actual machine state first and follow the manufacturer's defined recovery procedure, then verify motion in single-block or simulation mode.
Does G28 behave the same on CNC mills and lathes?
The axis conventions differ. A Haas mill example uses X/Y/Z, while a Haas lathe example uses X/Z and the U/W incremental addresses, and G28 U0 W0 returns to the machine zero in that lathe semantics. Treat each machine family's syntax on its own terms and verify against its manual.
How do I verify a G28 move is safe before running the program?
Confirm the controller and machine builder documentation, check whether the current mode is G90 or G91, simulate the program or run it in single-block mode, confirm the actual machine travel and tool envelope, and verify the compensation state. Only then run the program in the normal cycle.
What is the difference between G28 and G30?
G30 is a reference return to a second reference position where the control supports it. It is not automatically the tool-change position, and its availability and meaning depend on the controller and parameter settings. Use it only where your machine's documentation defines a second reference position.

Need a CNC partner who gets the details right?

G28 is one example of why process understanding matters on the shop floor. If you are sourcing machined parts, send us your drawing and we will review manufacturability, tolerances, and lead time against our in-house CNC, molding, and finishing capability.

Request a CNC Manufacturing Review

Xiamen Goldcattle Plastic & Metal Products Co., Ltd. — Founded in 1998. All six core processes performed in-house under one ISO 9001:2015 quality system.

Recommended Reading