Construction

Marlin G-code and M-code Reference for 3D Printers

The Marlin firmware commands 3D printers use most: G0/G1, G28, G29, G90/G91, G92, M104/M109, M140/M190, M106/M107, M82/M83, M84 and M500–M503, with their parameters and units.

In Marlin, G28 homes the printer, G29 probes the bed for leveling, G0/G1 move (with E for extrusion and F in mm/min), M104 sets the hotend temperature and continues while M109 waits for it, M140 / M190 do the same for the bed, M106 S0–255 sets the part-cooling fan (S255 = 100%) and M107 turns it off, M82 / M83 switch the extruder between absolute and relative, M84 turns the steppers off, and M500 saves settings to EEPROM. Temperatures are in °C unless changed with M149. Many commands exist only when the firmware is built with a matching option, noted below. Everything here is from the official Marlin G-code index (marlinfw.org, Marlin 2.x). The G-code meanings differ from CNC controls in places (M30 deletes an SD file, G76 calibrates the probe), so a mill program cannot be sent to a printer unchanged; see the M-code comparison.

Motion and positioning G-codes

CodeWhat it doesMain parameters (units)
G0, G1Linear move. On Cartesian and delta printers G0 is an alias for G1; slicers use G0 for travel and G1 for extrusion moves.X Y Z (mm, or inches after G20); E extruder (mm of filament); F feed rate (mm/min, applies to later moves too); S laser power (laser builds)
G2, G3Clockwise / counter-clockwise arc (needs ARC_SUPPORT). Arcs are cut into short straight segments (MM_PER_ARC_SEGMENT, default 1 mm).X Y end point; I J centre offset or R radius (mm), never both; E; F (mm/min); P full circles (ARC_P_CIRCLES)
G4Dwell: pause the command queue. G4 with no time works like M400.S seconds, or P milliseconds (S wins if both are given): G4 P500 = 0.5 s
G10, G11Firmware retract / recover, using the M207 / M208 settings (needs FWRETRACT).G10 S1 = swap retraction before an extruder change
G20, G21Inch / millimetre units (needs INCH_MODE_SUPPORT); millimetres are the default.—
G28Auto home: move each axis to its endstop. No letters = home all axes. Turns bed leveling off unless the firmware restores it.X Y Z home only those axes; O skip axes already trusted; R raise the nozzle first (mm); L restore leveling state
G29Bed leveling: probe the bed and enable compensation. Behaviour depends on the leveling system compiled in (mesh, bilinear, unified, linear or 3-point).See the page for your leveling type
G90Absolute positioning for all axes, including E unless M83 overrides it. This is the default.—
G91Relative positioning for all axes, including E unless M82 overrides it.—
G92Set the current position without moving, for example G92 E0 to zero the extruder.X Y Z E new position (mm). Since Marlin 1.1.0 the software endstops keep the physical limits.

Temperature, fan and extrusion M-codes

CodeWhat it doesParameters (units)Waits?
M104Set hotend target temperatureS target (°C); T hotend number; I material presetNo
M109Set hotend target and waitS target, waits only when heating; R target, waits for heating or cooling (°C); T hotendYes
M140Set bed target temperatureS target (°C); I material presetNo
M190Set bed target and waitS waits only when heating; R heating or cooling (°C); T cooling time (s)Yes
M105Report temperatures to the hostT hotend; R redundant sensorNo
M106Fan on / set speedS 0–255 (S255 = 100%, S128 ≈ 50%; no S = full); P fan numberNo
M107Fan offP fan numberNo
M82Extruder (E) absolute modeG90 / G91 clear itNo
M83Extruder (E) relative modeG90 / G91 clear itNo
M221Flow percentage for all E movesS percent (%); T extruderNo
M220Feed rate percentage for all movesS percent (%); B back up; R restoreNo
M302Cold-extrusion check (needs PREVENT_COLD_EXTRUSION)S minimum extrusion temperature (°C); P1 allow any temperatureNo
M149Temperature units (needs TEMPERATURE_UNITS_SUPPORT)C Celsius (default), F Fahrenheit, K KelvinNo

Steppers, motion limits and calibration

CodeWhat it doesParameters (units)
M17Enable steppersAxis letters, or none for all
M18, M84Disable steppers, or set the idle timeoutAxis letters, or none for all; S inactivity timeout (s), S0 disables it
M92Steps per unitX Y Z E (steps/mm; steps/degree on rotary or SCARA axes); T extruder
M201Maximum acceleration per axisX Y Z E (units/s²)
M203Maximum feed rate per axisX Y Z E (units/s, not mm/min)
M204Starting acceleration by move typeP printing, R retract, T travel (units/s²); S is legacy (sets P and T)
M205Advanced motion settingsX Y Z E jerk (units/s); J junction deviation; S / T minimum print / travel feed (units/s); B minimum segment time (µs)
M206Home offsets (not on delta)X Y Z (mm), added to the native home position
M211Software endstops on / offS1 on, S0 off
M420Bed leveling stateS1 enable (needs a valid mesh); Z fade height (mm, 0 = off); V print the mesh; L load a UBL slot
M851Probe offset from the nozzleX Y Z (mm). For Z: home, lower until the probe triggers (M119), read Z with M114 and negate it.
M900Linear Advance K factor (needs LIN_ADVANCE)K factor (0 disables); higher for flexible filament or a long path
M301Hotend PID values (needs PIDTEMP)P I D; E hotend index
M303PID autotuneE hotend (-1 = bed); S target (°C); C cycles (minimum 3, default 5); U use the result

Settings, SD card, host and safety

CodeWhat it doesNotes
M500Save settings to EEPROMSince Marlin 1.1.0 only changed bytes are written (needs EEPROM_SETTINGS).
M501Load settings from EEPROMNeeds EEPROM_SETTINGS.
M502Factory reset (in memory)Works without EEPROM; follow with M500 to make it permanent.
M503Report current settingsShows the settings in RAM, which may differ from EEPROM.
M20List SD card filesLists .gcode, .gco and .g files in 8.3 form with sizes.
M23Select SD fileFollow with M24 to start it.
M24Start or resume SD printS / T resume after power loss (POWER_LOSS_RECOVERY).
M25Pause SD printParks the nozzle if PARK_HEAD_ON_PAUSE is on.
M30Delete a file from the SD cardNot "program end" as on CNC controls.
M114Report current positionR real position (M114_REALTIME), D detail, E stepper position.
M115Firmware name, version and capabilitiesFor example FIRMWARE_NAME:Marlin 2.1.3.
M117Show a message on the LCDNeeds an LCD controller.
M119Report endstop and probe states"open" or "TRIGGERED".
M300Play a toneP duration (ms); S frequency (Hz).
M400Wait for all moves to finish—
M600Filament changeNeeds ADVANCED_PAUSE_FEATURE and an LCD; can be started by a runout sensor.
M112Full shutdown: steppers and heaters off, reset requiredNot a safety-rated emergency stop (Marlin's own warning).
M999Restart after a STOPHeaters stay off; S resumes without flushing the buffer.
T0–T7Select tool / extruderF feed rate for the change; with an MMU2, T0–T7 select a filament.

A start sequence built from Marlin's own examples

M140 S80        ; set bed to 80 °C, do not wait
M104 S185       ; set hotend to 185 °C, do not wait
G28             ; home all axes (turns leveling off)
M420 S1         ; turn bed leveling back on (stored mesh)
M190 S80        ; wait for the bed
M109 S185       ; wait for the hotend
G92 E0          ; zero the extruder
G1 F1500        ; feed rate 1500 mm/min for following moves
M83             ; relative extrusion

The temperatures are the values used in Marlin's documentation examples (M140 S80, M190 S80, M104 S185), not recommendations: use the temperatures on your filament's label. Setting both heaters first with M140/M104 and only then waiting with M190/M109 lets them warm up together. Marlin, like LinuxCNC, accepts ";" comments, but Haas and other Fanuc-style mills end the block at ";". To check the moves of a print file, paste the G0/G1 section into the G-code Explainer & Simulator (it reads the LinuxCNC and Haas dialects, not Marlin, so it flags E words and printer M-codes instead of explaining them). The Unit Converter turns °C into °F.

Units and traps

  • Feed rate units differ by command. F in G0/G1/G2/G3 is per minute (mm/min), but M203 maximum feed rate is per second (mm/s), and M201/M204 accelerations are mm/s². F1500 in a move is 25 mm/s.
  • Dwell units differ from CNC. Marlin G4 P is milliseconds and S is seconds; LinuxCNC G4 P is seconds.
  • M109 S vs R. S waits only when heating, so M109 S180 on a hotend at 220 °C continues at once; M109 R180 waits until it has cooled to 180 °C. M190 R70 T600 cools the bed to 70 °C slowly over 600 s (10 minutes) to reduce warping.
  • Blocking waits. M109 and M190 block new commands from the host. With EMERGENCY_PARSER enabled the host can send M108 to break out; M112 is acted on immediately only with EMERGENCY_PARSER.
  • G28 and leveling. By default G28 disables bed leveling; M420 S1 re-enables it, or build with ENABLE_LEVELING_AFTER_G28 / RESTORE_LEVELING_AFTER_G28.
  • Build options. Commands marked "needs …" only exist when Marlin was compiled with that option; otherwise the printer reports an unknown command. M115 with EXTENDED_CAPABILITIES_REPORT lists some of the enabled features (Cap:EEPROM:1, Cap:AUTOLEVEL:1 …).
  • Codes that mean something else on a CNC control: M30 deletes an SD file (CNC: program end), G76 is probe temperature calibration (CNC mills: fine boring; LinuxCNC: threading), M48 is a probe repeatability test (LinuxCNC: overrides on), and M104/M109 are probe-arm and user-input codes on Haas mills.

Sources

  • MarlinFirmware, Marlin G-code index, marlinfw.org/docs/gcode/ (pages G000-G001, G002-G003, G004, G010, G011, G020, G021, G028, G029, G076, G090, G091, G092, M000-M001, M003, M005, M007-M009, M017, M018, M020, M023–M025, M030, M048, M082, M083, M092, M104–M107, M109, M112, M114, M115, M117, M119, M140, M149, M190, M201, M203–M206, M211, M220, M221, M300–M303, M400, M420, M500–M503, M600, M851, M900, M999, T). The page sources were downloaded from github.com/MarlinFirmware/MarlinDocumentation (_gcode folder) on 6 October 2026. Used for: every code, parameter, unit and example value on this page.
  • LinuxCNC Project, G-Codes (G4 dwell in seconds) and Haas Automation mill M-code list (M104/M105, M109), for the CNC comparisons only; see the M-code reference for those sources.
  • This page covers Marlin only. Other printer firmware (Klipper, RepRapFirmware and others) is separate; check its own documentation.

Frequently asked questions

What is the difference between M104 and M109?

M104 sets a new hotend target temperature and carries on without waiting. M109 sets it and waits: with S it waits only while heating, with R it also waits for the hotend to cool to the target. M140 and M190 do the same for the heated bed.

What does G28 do in Marlin?

G28 homes the axes by driving each toward its endstop until it triggers. With no letters it homes all axes; G28 X Z homes only X and Z, and G28 O skips axes whose position is already trusted. By default G28 also turns bed leveling off, so follow it with M420 S1 (or G29) to turn leveling back on.

What do M82 and M83 mean?

M82 puts the extruder (E axis) in absolute mode and M83 in relative mode, independently of the X/Y/Z axes. G90 and G91 clear that setting, so a G91 after M82 makes E relative too.

How do I save settings in Marlin?

Change the setting (for example steps per mm with M92, or a probe offset with M851), then send M500 to save to EEPROM. M501 reloads the saved values, M502 resets to the firmware defaults in memory only (send M500 after it to make that permanent) and M503 prints the current settings.

What units does M106 use for fan speed?

M106 takes S from 0 to 255, which is the PWM duty: S255 is 100% and S128 about 50%. M106 with no S runs the fan at full speed, and M107 turns it off. P selects the fan when there is more than one.

Was this article helpful?