G28 — Reference Return in CNC Milling
G28 commands the machine to return a specified axis (or all axes) to the machine reference position — also called machine zero, home position, or the reference point established during machine startup. This is the position the machine knows with absolute certainty, regardless of any work offsets or coordinate shifts active in the program.
G28 is used at tool changes, at the end of programs, and any time the machine needs to return to a known mechanical position.
How G28 Works — The Intermediate Point
G28 does not simply rapid directly to the reference position. It moves through an intermediate point first:
- The machine moves to the intermediate point (the XYZ values in the G28 block)
- From the intermediate point, it rapids to the reference position
This two-step behavior exists to let you define a safe path to home. If the tool is buried in a pocket and you command G28 directly, the intermediate point lets you specify a clearance position before the machine moves toward home.
G28 X0. Y0. Z50. (move to X0,Y0,Z50 first, then go home)
The Standard Idiom: G91 G28 Z0
The most common G28 usage in milling programs is:
G91 G28 Z0.
This is almost always written in incremental mode (G91). Here's why:
In G91, Z0. means "move zero distance in Z from the current position." So the intermediate point is exactly where the tool already is. The machine does not move the Z axis to reach the intermediate point — it goes directly to the reference position from the current Z location.
In G90 (absolute), G28 Z0. would mean "move to Z0 (the part surface) first, then go home" — which would crash the tool into the part if it's currently above it.
The safe standard sequence at the end of a program:
G0 Z50. (retract to clearance height)
G91 G28 Z0. (from Z50, go home — no Z movement to intermediate point)
G90 (restore absolute mode)
G28 X0. Y0. (return X and Y to home — in absolute, X0Y0 is typically safe)
M30
G28 at Tool Changes
On machines with automatic tool changers, G28 Z0 (in G91) is required before M06 to ensure the spindle is at the tool change position:
G0 Z80. (retract above part and fixtures)
G91 G28 Z0. (Z to home — tool changer can now access the spindle)
G90
T2 M6 (tool change)
G0 G54 X0. Y0. S5000 M3 (position for new tool)
G43 H2 Z50.
Skipping G28 before M06 on machines where the tool changer requires Z home will cause a machine fault or alarm — the carousel cannot reach the spindle if Z is in the middle of travel.
G28 vs G53
G53 is an alternative way to move to machine coordinates:
G53 G0 Z0. (rapid to machine Z zero — no intermediate point)
G53 is non-modal and moves directly to machine coordinates in a single block. It does not go through the homing sequence that G28 uses. Some programmers prefer G53 for tool changes on machines where homing is not required — it is faster and more explicit.
The difference:
- G28 — performs the full reference return sequence (useful after a power cycle)
- G53 — moves directly to machine coordinates (faster, requires machine to be already homed)
G29 — Return from Reference Position
G29 is the complement of G28. After returning to the reference position with G28, G29 moves the machine back through the last intermediate point to a new XY position. It is rarely used in modern programming — most programs simply position with G0 after the tool change rather than using G29.
Common Mistakes
G90 G28 Z0. — In absolute mode, this moves the Z axis to Z0 (part surface) before going home. Almost always wrong, and a common crash. Always use G91 before G28.
G28 without retracting first — If the tool is engaged in the workpiece when G28 executes, the intermediate point move will drag the tool through the part. Always retract to a safe Z height before G28.
Forgetting G90 after G91 G28 — After G91 G28 Z0., the machine is still in incremental mode. If the next block has absolute coordinates, they will be executed as incremental distances. Always restore G90 immediately after G28.
G91 G28 Z0. (home Z)
G90 (restore absolute — don't forget this)
T2 M6
Simulate G28 Before Running
G28 behavior in G90 vs G91 is one of the most common sources of unexpected machine movement in CNC programs. The difference between G28 Z0. and G91 G28 Z0. is a single two-character prefix that determines whether the tool crashes into the part or moves safely to home. Load your program in Eureka3X to verify the G28 path on the full 3D machine model.
Try Eureka3X free for 30 days →