G54.APP

G-code deep dive

G28 & G30: Return to Home / Reference Position

G28G28.1G29G30G30.1G27

G28 sends the machine to its stored reference position — for most machines, home. G30 does exactly the same thing to a second stored position (commonly the tool-change spot). Both look trivial and both hide the same trap: the block's axis words are not a destination. They're an intermediate point the machine visits on the way.

G28           ; all axes straight to the reference position
G28 Z0        ; first move to work Z0 (!), THEN home Z
G91 G28 Z0    ; the safe idiom: zero-length incremental move, then home Z
G90           ; ...and restore absolute mode immediately

That middle line is one of the most copied — and most misunderstood — lines in CNC. In absolute mode, Z0 is work Z0. With a typical work offset touched off at the part top, "go home via work Z0" means dropping to the stock surface (or into a fixture) before retracting. The G91 G28 Z0 idiom survives because it makes the intermediate hop a zero-length move — but it leaves the control in incremental mode, which is why the G90 chaser matters just as much.

Why the intermediate point exists

The two-step move let 1980s programs route around fixtures with no machine-coordinate motion command: pull to a safe spot, then home. Modern practice has a cleaner tool for "go to a machine position":

G53 G0 Z0          ; machine Z0 (top of travel), no intermediate point
G53 G0 X-10 Y-500  ; park — explicit, absolute, no modal side effects

Where the post supports it, G53 moves are the recommended replacement for G28 gymnastics — nothing modal changes and nothing is implied.

OperationLinuxCNCGRBLCentroidFANUCMach3Mach4HaasNotes
Return to reference position (home) G28 G28 G28 G28 G28 G28 G28 GRBL/Mach: pre-defined stored position.
Store the G28 reference point G28.1 G28.1 — — G28.1 G28.1 —
Return from reference (via intermediate point) G29 — G29 G29 G29 G29 G29
Return to secondary reference G30 G30 G30 G30 G30 G30 —
Store the G30 reference point G30.1 G30.1 — — G30.1 G30.1 —
Reference-position check — — — G27 — — — Verifies the machine is at home.

— means the control has no equivalent code. Full cross-control tables: the complete G-code & M-code reference.

Setting and checking the positions

Common mistakes

Frequently asked questions

What does G28 do in G-code?

It returns the machine to its stored reference position (usually machine home) — but via an intermediate point. Axis words in the block are the intermediate point, in the current (work!) coordinate system. Bare G28 goes straight home; G28 Z0 goes to work Z0 first, then home.

Why did G28 move my machine somewhere unexpected?

Because the axis words in a G28 block are an intermediate stop interpreted in work coordinates, not a target in machine coordinates. G28 Z0 with a deep work offset means 'go to work Z0' — possibly down into the part — 'then home'. The safe idiom is G91 G28 Z0 (zero incremental move, then home in Z), immediately followed by G90.

What is G30 for?

A second stored position, same semantics as G28. Shops typically keep G28 as machine home and set G30 at the tool-change or pallet position. FANUC-style posts commonly send Z home with G30 before a tool change.

How do I set where G28 returns to?

On controls with G28.1/G30.1 (LinuxCNC, GRBL, Mach), jog to the position and run G28.1 — the current spot is stored. On FANUC-style controls, the reference is fixed by homing (or set by parameter), not by a program command.

See it, don't guess it

Paste a program into the free G54.APP viewer and watch these codes execute — toolpaths, stock removal, and machine state, live in your browser. Nothing is uploaded.

Open the G-code viewer