G-codeCoordinate SystemMill · Lathe · 3D printer

G27, G28, G29 & G30: Reference Point Return

G28 sends an axis to machine home, the fixed position the machine finds when it references, and it gets there in two moves: first to an intermediate point you give it, then home. G30 does the same thing to a second reference point, which on most machines is the tool change height. G29 is the way back out, from home through that same intermediate point to a position you name. G27 moves to a position and alarms if that position turns out not to be the reference point, so it checks rather than retracts.

Syntax

G28 X__ Y__ Z__      Home, via the intermediate point X, Y, Z
G91 G28 Z0.          Home Z with no intermediate move, the usual safe retract
G30 P__ X__ Y__ Z__  2nd, 3rd or 4th reference point, 2nd if P is left off
G29 X__ Y__ Z__      Out from the reference point, through the stored intermediate point
G27 X__ Y__ Z__      Position, then alarm if the axis is not at the reference point

Parameters

AddressMeaningNotes
X Y Z on G28 and G30Intermediate pointWork coordinates under G90, distance from where the axis stands under G91. Only the axes you name move
X Y Z on G29Final positionThe path runs from the reference point, through the point the last G28 stored, then here
X Y Z on G27Position to checkReached at rapid, then compared against the reference point
P on G30Reference point numberP2 second, P3 third, P4 fourth

Nothing in the block says where home is. The reference points are machine data, set when the machine is commissioned and read from parameters at run time, so the same four lines put the spindle in a different place on a different machine.

Example

O0006 (SLOTTED COVER, 20MM 6082 PLATE)
G21 G17 G40 G49 G80 G90          (safe start block)
T04 M06                          (16mm three flute cutter)
G54                              (part zero at the left end of the plate)
S4500 M03                        (226m/min in aluminium)
G00 X-20. Y12.                   (clear of the plate, left of the slot)
G43 H04 Z30. M08                 (tool length comp on, flood coolant)
G01 Z-5.8 F600                   (roughing depth, 0.2mm on the floor)
X160. F1400                      (through the slot in one pass)
G00 Z30. M09                     (clear of the strap clamp)
G49                              (comp off before any reference move)
G91 G28 Z0.                      (Z alone to machine home, X and Y stay put)
G90 G28 X-20. Y200.              (out past the fixture, then X and Y home)
M05
M00                              (first off, operator checks the slot depth)
S4500 M03
G29 X-20. Y12.                   (back in through X-20. Y200. to the slot start)
G43 H04 Z30. M08
G01 Z-6. F600                    (finish pass on the floor)
X160. F1400
G00 Z30. M09
G49
G91 G30 Z0.                      (Z to the 2nd reference point, the tool change height)
M30

Controller differences

ControlBehaviour
FanucThe intermediate point is read in whichever of G90 or G91 is live, which is the whole reason G91 G28 Z0. is written the way it is: zero distance to the intermediate point, then straight home. The manual tells you to cancel tool length and cutter compensation before G27 and G28. The 2nd, 3rd and 4th reference points live in parameters 1241, 1242 and 1243 as machine coordinates.
HaasSame intermediate point rule, but a G28 block with no axis word at all sends every axis to machine zero, so the word you leave off changes the move. The control also has its own Home G28 key on the panel, which is not the same thing as the block.
Siemens 840DNo G28, G29 or G30 in the native language. Reference point approach is G74 X1=0 Y1=0 Z1=0 and the fixed point approach that replaces G30 is G75 FP=1 X1=0, each in a block of its own. Worth knowing that G74 is a tapping cycle in Fanuc dialect, so a post set to the wrong dialect writes something that runs and is not what anyone drew.
MazakEIA/ISO programs run G28, G29 and G30 as on Fanuc. A Mazatrol conversational program has no return block to write: the retract before each tool change belongs to the unit.
GrblG28 and G30 do not home anything. They rapid to a position stored beforehand with G28.1 or G30.1 and held in EEPROM, while homing is the $H cycle against the limit switches. G27 and G29 are not in the supported list and stop the stream with error:20.
MarlinAll four numbers mean something else. G28 homes to the endstops with no intermediate point, and G28 X homes X alone. G29 runs bed levelling, G30 probes a single point, G27 parks the toolhead. A mill program pasted into printer firmware therefore probes the bed where it meant to come home.

What goes wrong

Writing G28 X0. Y0. in G90 drags the cutter across the top of the job on the way home. Those two words never mean the home position: they set the intermediate point, and under G90 that point sits at part zero of the live work offset, so the tool rapids to the corner of the job at whatever height it happens to be. Retract with G91 G28 Z0. on a line of its own, then send X and Y wherever you like.

Second is what is still switched on when the block runs. With G43 live the intermediate point carries the tool length with it, and Fanuc's manual tells you to cancel compensation before G27 and G28 for exactly that reason. G49 on the line above costs nothing.

Third is G30 landing somewhere else on the machine next door. The second reference point is machine data, parameter 1241 on a Fanuc, set by whoever commissioned that spindle, so a program that reaches a clear tool change position on one machine swings into a fixture on another.

Fourth is Grbl. G28 there runs no homing cycle whatsoever. It rapids to whatever was last stored with G28.1, and homing is $H. On a controller nobody has taught, that stored position sits at machine zero and the gantry leaves at full rapid.

Last, G27 against a live work offset. The position is read in the active coordinate system, so G27 X0. Y0. drives to part zero, works out that part zero is not the reference point, and alarms after the move rather than before it.

Updated 18 Sep 2026