These are the G-codes with which the Marlin firmware moves the machine and sets its coordinates, as Marlin’s own documentation describes them. Many exist only when the firmware was built with a named configuration option; the option is given under “Needs”. A version number after “since” is the first Marlin release the documentation gives for a code or parameter. Other firmwares can read the same numbers differently; compare the command register.
Positions and distances are in the current units, millimetres unless
G20 has chosen inches. In the tables, pos is a decimal number.
The axes A, B and C (since 2.0.9) and
U, V and W (since 2.1) exist only on builds that
define a fourth to ninth axis: a stepper driver I_DRIVER_TYPE,
J_DRIVER_TYPE, K_DRIVER_TYPE, U_DRIVER_TYPE,
V_DRIVER_TYPE or W_DRIVER_TYPE and, for the first three, the
axis name set with AXIS4_NAME to AXIS6_NAME.
G0 and G1: linear move
Since 1.0.0-beta. Queues a straight move on which all the named axes arrive
together. The command returns to the parser once the move is queued, though it may
wait for a free place in the queue. Slicers by convention write G0 for
travel and G1 for moves that extrude. On Cartesian and delta machines
G0 is a plain alias of G1; on SCARA machines it is a fast
move that is not a straight line. Marlin 2.0 can keep a separate default feed rate
for G0.
| Parameter | Meaning |
|---|---|
X Y Z pos | Target on that axis; optional |
A B C U V W pos | Target on the extra axes; optional |
E pos | Extruder position, measured as filament fed into the extruder; optional |
F rate | Feed rate in units per minute, for this and later moves. It is read as in LinuxCNC’s default state (units per minute, CANON_XYZ reference) |
S power | Laser power for the move. Since 2.1.1; needs LASER_FEATURE |
In relative mode (G91) coordinates are added to the previous position,
and under M83 so is E. One linear move may reach the planner
as several shorter ones because of kinematics or bed levelling.
G1 F1500 ; feed rate for what follows
G92 E0
G1 X50 Y25.3 E22.4 ; straight move while extruding
G2 and G3: arc or circle
Since 1.0.0-beta; needs ARC_SUPPORT. G2 goes clockwise and
G3 anticlockwise from the current position to the given end point. With
CNC_WORKSPACE_PLANES the arc may lie in the XY, ZX or YZ plane.
| Parameter | Meaning |
|---|---|
X Y Z, A B C U V W pos | End coordinates; optional, subject to the rules of the two forms below |
I offset | Centre, as an offset from the current X position |
J offset | Centre, as an offset from the current Y position |
R radius | Radius from the current XY position, instead of I and J |
E pos | Extrusion between start and end; optional |
F rate | Feed rate, applied along the helix when X, Y and Z all take part; stays in force |
P count | Number of complete circles; needs ARC_P_CIRCLES |
S power | Laser power. Since 2.0.8 |
- I/J form: at least one of
IandJ. Leaving outXandYdraws a full circle. The end point is not checked against the radius; the arc ends at the angle of the destination. - R form: needs
XorY, and one of them must differ from the current position. - Mixing
RwithIorJis an error.
The firmware draws an arc as short straight segments, of length
MM_PER_ARC_SEGMENT (1 mm by default). Movement on Z and on the
extra axes is spread evenly over the arc.
G2 X125 Y32 I10.5 J10.5 ; clockwise arc
G3 X2 Y7 I-4 J-3 ; anticlockwise from 9,6
G3 X2 Y7 R5 ; the same arc by radius
G2 I20 J20 ; full circle
G4: dwell
Since 1.0.0-beta. Pauses the command queue.
| Parameter | Meaning |
|---|---|
P time | Duration in milliseconds, a whole number |
S time | Duration in seconds, a whole number; wins if P is also given |
With neither it behaves in effect as M400, waiting for queued moves.
M0 and M1 give a pause that the user can interrupt.
G5: cubic Bézier spline
Since 1.1.0. Draws a cubic curve in the XY plane; naming any axis other than X and Y
for its geometry is an error (E may be given). The first control point is
the current position and the last is X Y. The two between
are the start plus I J and the end plus P
Q.
| Parameter | Meaning |
|---|---|
X, Y pos | End point; required |
I, J offset | First inner control point, from the start. Needed on the first G5 of a series; afterwards give both or neither. Left out, they are minus the previous P and Q, so the curve joins smoothly |
P, Q offset | Second inner control point, from the end; required |
E pos | Filament fed over the curve; optional |
F rate | Highest feed rate over the curve and for later moves. The documentation gives this one in units per second |
S power | Laser power. Since 2.0.8 |
The documentation’s notes also say that omitted I and J
count as zero offsets; its fuller description is the rule given in the table.
G0 X0 Y0
G5 I0 J3 P0 Q-3 X1 Y1
G5 P0 Q-3 X2 Y2 ; continues smoothly
G6: direct stepper move
Needs DIRECT_STEPPING. A host first loads pre-computed binary step data
into pages in the printer’s RAM, over a parallel protocol on the USB serial link;
G6 then runs a page, without interpolation or kinematics. The
documented host program is Step Daemon. The documentation warns to home before such
moves and to use the feature with great care, as moves made from the control panel may
be lost to the host.
| Parameter | Meaning |
|---|---|
I index | Page number |
R rate | Steps per second; remembered for later calls |
S count | Number of steps; the most possible when left out |
X Y Z E 0 or 1 | Direction, 1 positive and 0 negative; remembered; not used by page formats that carry direction |
G10 and G11: firmware retraction
Since 1.0.0-beta; need FWRETRACT. G10 retracts as set with
M207: a retract move and an optional Z lift. G11 undoes it,
lowering Z and pushing back the matching length plus the extra length set with
M208, at the M208 rate. A repeated retract without a recover
between is ignored, and so is a repeated recover.
| Form | Meaning |
|---|---|
G10 | Retract |
G10 S1 | Longer retraction for a change of extruder; needs more than one extruder. The recover after the tool change is chosen to match |
G11 | Recover; picks plain or swap recovery itself. No parameters are listed |
G12: clean the nozzle
Since 1.1.0; needs NOZZLE_CLEAN_FEATURE, whose settings in
Configuration.h give the defaults. It wipes the nozzle on a cleaning
area within reach. With NOZZLE_CLEAN_GOBACK the nozzle then returns to
where it was.
| Parameter | Meaning |
|---|---|
P 0–2 | Pattern: 0 straight strokes back and forth, 1 zigzag, 2 circle |
S count | Repetitions of the pattern (the stroke count otherwise defaults to NOZZLE_CLEAN_STROKES) |
T count | Triangles in the zigzag |
R radius | Radius of the circle |
E 0 or 1 | 1 loosens the software endstops while cleaning; they stay active by default |
X Y Z | Flags naming the motions to include when cleaning with limited axes; leave all out for unlimited cleaning |
G12 P1 S1 T3 ; one zigzag of 3 triangles
G12 P2 S1 R10 ; one circle of radius 10
G17 to G21: plane and units
| Code | Meaning | Needs |
|---|---|---|
G17 | Arcs and splines in the XY plane | CNC_WORKSPACE_PLANES |
G18 | ZX plane | CNC_WORKSPACE_PLANES |
G19 | YZ plane | CNC_WORKSPACE_PLANES |
G20 | Positions, offsets, rates and accelerations in later G-code are inches. Since 1.1.0 | INCH_MODE_SUPPORT |
G21 | The same values are millimetres. Since 1.1.0 | INCH_MODE_SUPPORT |
None of these takes a parameter.
G26: mesh validation pattern
Since 1.1.0; needs G26_MESH_VALIDATION. Prints a single layer over the
whole bed to show how good each point of the levelling mesh is. Before 1.1.6 it
needed unified bed levelling; since 1.1.7 it also works with mesh and bilinear
levelling.
| Parameter | Meaning | Otherwise |
|---|---|---|
B temp | Bed temperature | 60 °C |
H temp | Nozzle temperature | 205 °C |
I index | Material preset to use. Since 2.0.6; the documentation says it overrides S | |
C 0 or 1 | Continue with the closest point | Off |
D | Disable levelling compensation | Enabled |
F size | Filament diameter | 1.75 mm |
S size | Nozzle size | 0.4 mm |
L height | Layer height | |
O length | Ooze amount, pushed out at the start | 0.3 mm |
P length | Prime length | |
Q factor | Multiplier for the pattern’s retraction (1.0 mm) and recovery (1.2 mm) | |
R count | Number of repetitions | 999 |
U value | Random deviation; U without a value means 50 | |
K 0 or 1 | Leave the heaters on afterwards | |
X, Y pos | Position | The current one |
G27: park the toolhead
Since 1.1.0; needs NOZZLE_PARK_FEATURE. Raises Z and moves to the XY and
Z position set in NOZZLE_PARK_POINT; the smallest raise is
NOZZLE_PARK_Z_RAISE_MIN.
P value (since 2.0.0) | Behaviour before and during parking |
|---|---|
| 0, the default | Raise Z by the minimum raise, with the park Z as the least height, then move in XY |
| 1 | Go to the park Z absolutely, then XY. This can move the nozzle down |
| 2 | Raise Z by the park Z value, then XY |
| 3 (since 2.1.3) | Raise by the minimum raise only; no XY move |
| 4 (since 2.1.3) | XY move only; no raise |
G28: home
Moves axes to their endstops to establish a known position; with no axis named, all
of them. Homing is needed before bed probing (G29), M48 and
some other procedures. By default G28 switches bed levelling off and
M420 S switches it on again; ENABLE_LEVELING_AFTER_G28
always turns it on and RESTORE_LEVELING_AFTER_G28 puts back the earlier
state.
| Parameter | Meaning |
|---|---|
X Y Z, A B C U V W | Flags naming the axes to home |
O | Skip homing when the position is already trusted. Since 1.1.9 |
R height | Distance to raise the nozzle first. Since 1.1.9 |
L 0 or 1 | Restore the bed levelling state afterwards; listed as true by default |
H | Keep the current X and Y instead of moving to the safe position before homing Z. Needs Z_SAFE_HOMING |
P 0 or 1 | Precise Z homing: after homing, probe at the same XY point and correct Z by the error; nothing happens if Z is not homed or the probe fails. Since 2.1.3; needs PRECISE_Z_HOMING |
Homing may bump each endstop a second time more slowly, as set by
[XYZ]_HOME_BUMP_MM and HOMING_BUMP_DIVISOR.
G28 ; all axes
G28 X Z ; two axes
G28 O ; only axes not yet trusted
G53 to G59.3: workspaces
Need CNC_COORDINATE_SYSTEMS. A workspace is an XYZ offset from the
machine’s own space. All start at zero, or are restored from EEPROM when that is
enabled.
| Code | Selects |
|---|---|
G53 | The machine’s own space (workspace 0). In front of a move on the same line it applies to that move; alone on a line it makes that space current |
G54, G55, G56 | Workspaces 1, 2 and 3 |
G57, G58, G59 | Workspaces 4, 5 and 6 |
G59.1, G59.2, G59.3 | Workspaces 7, 8 and 9 |
With a workspace selected, G92 changes its offset.
G53 G0 X0 Y0 Z0 ; one move in machine coordinates
G59.1 ; workspace 7
G92 X0 Y0 ; call this point its origin
G60 and G61: stored positions
Need SAVED_POSITIONS, which also sets how many slots there are. Slots
are held in RAM and start empty; restoring an empty slot does nothing.
| Form | Meaning |
|---|---|
G60 | Report all stored positions. Since 2.1.3 |
G60 Sslot | Store the current position of all axes; the slot is 0 if S is left out |
G60 Dslot | Delete one slot; D with no number deletes all. Since 2.1.3 |
G60 Qslot | Move back to a slot, the same as G61 S. Since 2.1.3, as are its F and axis parameters |
G61 Sslot | Move to a slot; slot 0 if S is left out |
Parameter of G61 and G60 Q | Meaning |
|---|---|
F rate | Wanted feed rate; the actual one may be limited |
X Y Z [offset] | Restore only the named axes, each with an optional distance added. With no axis named, all are restored |
E [offset] | Restore the extruder position; the extruder is not moved |
G60 S0 ; remember this position
G60 Q5 X10 Y Z E ; back to slot 5, X offset by 10
G61 S4 X Y50 Z E ; back to slot 4, Y offset by 50
G80: cancel the motion mode
Since 2.0.0; needs GCODE_MOTION_MODES. With that option each
G0, G1, G2, G3, G5
and G38.x sets a motion mode, so that a following line may give only
coordinates and feed rate. G80 ends the mode; a bare coordinate line is
then an unknown command. It has no parameters, and Marlin has no canned cycles.
G90, G91 and G92: positioning
| Code | Meaning |
|---|---|
G90 | Absolute positions, the default, for the extruder too unless M83 says otherwise. Since 1.0.0-beta |
G91 | Relative positions, for the extruder too unless M82 says otherwise. Since 1.0.0-beta |
G92 X Y Z A B C U V W E pos | Without moving, declare that the named axes are now at these values; each is optional |
G92.1 | Reset the selected workspace to the machine’s own space; needs CNC_COORDINATE_SYSTEMS |
Since Marlin 1.1.0 the software endstops move with G92, so that the
physical limits stay where they are; it can no longer be used to go below the bed.
G92 X10 E90 ; X is now 10, extruder 90
Sources
- MarlinDocumentation – Marlin’s own documentation source, one file per command in
docs/gcode/(G000 to G012, G017 to G028, G053 to G061, G080, G090 to G092), as of 3 December 2026