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
| Code | What it does | Main parameters (units) |
|---|---|---|
| G0, G1 | Linear 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, G3 | Clockwise / 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) |
| G4 | Dwell: 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, G11 | Firmware retract / recover, using the M207 / M208 settings (needs FWRETRACT). | G10 S1 = swap retraction before an extruder change |
| G20, G21 | Inch / millimetre units (needs INCH_MODE_SUPPORT); millimetres are the default. | — |
| G28 | Auto 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 |
| G29 | Bed 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 |
| G90 | Absolute positioning for all axes, including E unless M83 overrides it. This is the default. | — |
| G91 | Relative positioning for all axes, including E unless M82 overrides it. | — |
| G92 | Set 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
| Code | What it does | Parameters (units) | Waits? |
|---|---|---|---|
| M104 | Set hotend target temperature | S target (°C); T hotend number; I material preset | No |
| M109 | Set hotend target and wait | S target, waits only when heating; R target, waits for heating or cooling (°C); T hotend | Yes |
| M140 | Set bed target temperature | S target (°C); I material preset | No |
| M190 | Set bed target and wait | S waits only when heating; R heating or cooling (°C); T cooling time (s) | Yes |
| M105 | Report temperatures to the host | T hotend; R redundant sensor | No |
| M106 | Fan on / set speed | S 0–255 (S255 = 100%, S128 ≈ 50%; no S = full); P fan number | No |
| M107 | Fan off | P fan number | No |
| M82 | Extruder (E) absolute mode | G90 / G91 clear it | No |
| M83 | Extruder (E) relative mode | G90 / G91 clear it | No |
| M221 | Flow percentage for all E moves | S percent (%); T extruder | No |
| M220 | Feed rate percentage for all moves | S percent (%); B back up; R restore | No |
| M302 | Cold-extrusion check (needs PREVENT_COLD_EXTRUSION) | S minimum extrusion temperature (°C); P1 allow any temperature | No |
| M149 | Temperature units (needs TEMPERATURE_UNITS_SUPPORT) | C Celsius (default), F Fahrenheit, K Kelvin | No |
Steppers, motion limits and calibration
| Code | What it does | Parameters (units) |
|---|---|---|
| M17 | Enable steppers | Axis letters, or none for all |
| M18, M84 | Disable steppers, or set the idle timeout | Axis letters, or none for all; S inactivity timeout (s), S0 disables it |
| M92 | Steps per unit | X Y Z E (steps/mm; steps/degree on rotary or SCARA axes); T extruder |
| M201 | Maximum acceleration per axis | X Y Z E (units/s²) |
| M203 | Maximum feed rate per axis | X Y Z E (units/s, not mm/min) |
| M204 | Starting acceleration by move type | P printing, R retract, T travel (units/s²); S is legacy (sets P and T) |
| M205 | Advanced motion settings | X Y Z E jerk (units/s); J junction deviation; S / T minimum print / travel feed (units/s); B minimum segment time (µs) |
| M206 | Home offsets (not on delta) | X Y Z (mm), added to the native home position |
| M211 | Software endstops on / off | S1 on, S0 off |
| M420 | Bed leveling state | S1 enable (needs a valid mesh); Z fade height (mm, 0 = off); V print the mesh; L load a UBL slot |
| M851 | Probe offset from the nozzle | X Y Z (mm). For Z: home, lower until the probe triggers (M119), read Z with M114 and negate it. |
| M900 | Linear Advance K factor (needs LIN_ADVANCE) | K factor (0 disables); higher for flexible filament or a long path |
| M301 | Hotend PID values (needs PIDTEMP) | P I D; E hotend index |
| M303 | PID autotune | E hotend (-1 = bed); S target (°C); C cycles (minimum 3, default 5); U use the result |
Settings, SD card, host and safety
| Code | What it does | Notes |
|---|---|---|
| M500 | Save settings to EEPROM | Since Marlin 1.1.0 only changed bytes are written (needs EEPROM_SETTINGS). |
| M501 | Load settings from EEPROM | Needs EEPROM_SETTINGS. |
| M502 | Factory reset (in memory) | Works without EEPROM; follow with M500 to make it permanent. |
| M503 | Report current settings | Shows the settings in RAM, which may differ from EEPROM. |
| M20 | List SD card files | Lists .gcode, .gco and .g files in 8.3 form with sizes. |
| M23 | Select SD file | Follow with M24 to start it. |
| M24 | Start or resume SD print | S / T resume after power loss (POWER_LOSS_RECOVERY). |
| M25 | Pause SD print | Parks the nozzle if PARK_HEAD_ON_PAUSE is on. |
| M30 | Delete a file from the SD card | Not "program end" as on CNC controls. |
| M114 | Report current position | R real position (M114_REALTIME), D detail, E stepper position. |
| M115 | Firmware name, version and capabilities | For example FIRMWARE_NAME:Marlin 2.1.3. |
| M117 | Show a message on the LCD | Needs an LCD controller. |
| M119 | Report endstop and probe states | "open" or "TRIGGERED". |
| M300 | Play a tone | P duration (ms); S frequency (Hz). |
| M400 | Wait for all moves to finish | — |
| M600 | Filament change | Needs ADVANCED_PAUSE_FEATURE and an LCD; can be started by a runout sensor. |
| M112 | Full shutdown: steppers and heaters off, reset required | Not a safety-rated emergency stop (Marlin's own warning). |
| M999 | Restart after a STOP | Heaters stay off; S resumes without flushing the buffer. |
| T0–T7 | Select tool / extruder | F 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.