Friday, September 26, 2025
HomeCodingG-Codes - Wiki

G-Codes – Wiki

About G-Code

At the basic level, G-Code is the language by which people tell computerized CNC /3D Printer machines how to make something.

G-Code is the instruction code that tells a 3D printer what to do. For example, the G-Code G0 X10 tells the machine to move the current tool to X position 10.

Marlin’s GCode is loosely based on the language specification for the NIST RS274NGC Interpreter, but departs radically in its specific implementation details. (For example, RepRap G-Code doesn’t care about “modal groups.”)

I heard of many 3D printer gurus that tweaking and setting the G-Code on a manual level is a bit dangerous for your machine. “No, we don’t ever recommend manually changing G-code. There’s far too much room to send a command (or delete a command) that would cause physical damage to a printer if done incorrectly.”

G-Code in Marlin – The simple layout

Movement

G0 -> G1
G1 – Coordinated Movement X Y Z E
G2 – Clockwise Arc
G3 – Counter-clockwise Arc
G4 – Dwell S or P
G92 – Set the “current position” for X Y Z E
M0 – Wait for user, with optional prompt message (requires LCD controller)
M1 -> M0
M400 – Finish all moves
M999 – Restart after an Emergency Stop

SD Card

M20 – List SD card
M21 – Init SD card
M22 – Release SD card
M23 – Select an SD file by DOS path (M23 path/to/filename.g)
M24 – Start/resume SD print
M25 – Pause SD print
M26 – Set SD position in bytes
M27 – Report SD print status
M28 – Start SD write
M29 – Stop SD write
M30 – Delete file from SD
M31 – Print the time since SD print started, or since the most recent M109 command
M32 – Select file and start SD print. Can be used within G-Code files to include other files.
M540 – Set the state of the Abort on Endstop Hit flag.
M928 – Start SD logging. Stop logging with M29.

Hardware Control

M42 – Change pin status via gcode: P S. If P is omitted the onboard LED pin will be used. M42 P9 S1 ; set PIN 9 to 1.
M80 – Turn on Power Supply
M81 – Turn off Power Supply
M85 – Set inactivity shutdown timer with parameter S. Disable with “M85” or “M85 S0”.
M112 – Emergency stop. Requires hardware reset!!
M226 – Wait for a pin to be in some state: P S
M410 – Quickstop. Abort all planned moves, stopping the printer.

Temperature

M104 – Set extruder target temperature
M105 – Request the current temperature of all heaters
M106 – Set the fan speed
M107 – Set the fan speed to 0 (thus turning it off)
M109 – Wait for an extruder to reach its target temperature. Optionally set the target temperature. Optionally enable AUTOTEMP.
M140 – Set heated bed target temperature
M145 – Set “heatup state” values for the LCD Menu
M190 – Wait for the heated bed to reach its target temperature. Optionally set the target temperature.
M301 – Set PID parameters P I and D
M302 – Allow cold extrudes, or set the minimum extrusion temperature
M303 – PID relay autotune S sets the target temperature. (default target temperature = 150C)
M304 – Set bed PID parameters P I and D

Messages

M111 – Set debug flags
M114 – Output current position to serial port
M115 – Capabilities string
M117 – Display message text on the LCD
M119 – Output Endstop status to serial port

Endstops

M120 – Enable endstop detection
M121 – Disable endstop detection

Special Features

M126 – Solenoid Air Valve Open. (Requires BARICUDA)
M127 – Solenoid Air Valve Closed. (Requires BARICUDA)
M128 – EtoP Open. (Requires BARICUDA)
M129 – EtoP Closed. (Requires BARICUDA)
M150 – Set BlinkM RGB Color via I2C. (Requires BLINKM)
M240 – Trigger a camera to take a photograph. (Requires CHDK or PHOTOGRAPH_PIN)
M250 – Set LCD contrast
M280 – Set servo position (absolute)
M300 – Play a beep sound. (Requires BEEPER_PIN or LCD_USE_I2C_BUZZER)
M380 – Activate solenoid on active extruder. (Requires EXT_SOLENOID)
M381 – Disable all solenoids. (Requires EXT_SOLENOID)
M600 – Pause for filament change. (Requires FILAMENTCHANGEENABLE)

Units and Measures

G90 – Use Absolute Coordinates
G91 – Use Relative Coordinates
M82 – Set E codes absolute (default)
M83 – Set E codes relative while in Absolute Coordinates (G90) mode
M92 – Set axis_steps_per_unit – same syntax as G92
M200 – Set filament diameter and E axis units to mm^3
M201 – Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000)
M202 – Set max acceleration in units/s^2 for travel moves (M202 X1000 Y1000) Unused in Marlin!!
M203 – Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in mm/sec

M204 – Set default acceleration: P for Printing moves, R for Retract only (no X, Y, Z) moves and T for Travel (non printing) moves (ex. M204 P800 T3000 R9000) in mm/sec^2
M205 – Advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X=maximum xy jerk, Z=maximum Z jerk, E=maximum E jerk
M206 – Set additional homing offset
M218 – Set hotend offset (in mm): T X Y
M220 – Set speed factor override percentage: S
M221 – Set extrude factor override percentage: S

Firmware Retraction

G10 – Retract filament according to settings of M207
G11 – Retract recover filament according to settings of M208
M207 – Set retract length S[positive mm] F[feedrate mm/min] Z[additional zlift/hop], stays in mm regardless of M200 setting
M208 – Set recover=unretract length S[positive mm surplus to the M207 S*] F[feedrate mm/s]
M209 – S enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction

Z Probe

G28 – Home one or more axes.
G29 – Probe the bed Z height at multiple points and enable bed leveling compensation.
G30 – Probe the bed Z height at the current XY position.
G31 – Dock Z Probe sled.
G32 – Undock Z Probe sled.
M48 – Measure Z Probe repeatability.
M401 – Lower Z-probe.
M402 – Raise Z-probe.
M420 – Enable or disable Mesh Bed Leveling.
M421 – Set a single Mesh Bed Leveling Z coordinate: X Y Z

Filament Diameter

M404 – Set (or display) Nominal Filament Diameter in mm: N
M405 – Turn on Filament Sensor extrusion control: [D] to set distance (in cm) from sensor to extruder
M406 – Turn off Filament Sensor extrusion control
M407 – Display measured Filament Diameter

EEPROM Settings

M500 – Save current settings to EEPROM.
M501 – Load stored settings from EEPROM.
M502 – Revert to the default “factory settings.” ””’Does not store them in EEPROM!””’
M503 – Print current settings (from memory, not EEPROM).

Delta

M665 – Set Delta configurations: L R S
M666 – Set Delta endstop adjustment: X Y Z
M605 – Set dual x-carriage movement mode: S [ X R ]

Stepper Drivers

M17 – Enable/Power all stepper motors
M18 -> M84
M84 – Disable steppers until the next move, or set the inactivity timeout after which steppers should be disabled.
M907 – Set digital trimpot motor current using axis codes.
M908 – Control digital trimpot directly.
M350 – Set microstepping mode.
M351 – Toggle MS1 MS2 pins directly to set microstepping.

SCARA

”May change to suit future G-code standards”
M360 – SCARA calibration: Move to cal-position ThetaA (0 deg calibration)
M361 – SCARA calibration: Move to cal-position ThetaB (90 deg calibration – steps per degree)
M362 – SCARA calibration: Move to cal-position PsiA (0 deg calibration)
M363 – SCARA calibration: Move to cal-position PsiB (90 deg calibration – steps per degree)
M364 – SCARA calibration: Move to cal-position PSIC (90 deg to Theta calibration position)
M365 – SCARA calibration: Scaling factor, X, Y, Z axis

Host Printing

M110 – Set the current Line Number

 

Håkan Fägnell
Håkan Fägnellhttps://3dprinterchat.com/
Håkan Fägnell Started 3DPrinterChat.com and is a content marketer who formerly worked out of AddGeek´s Stockholm office. A writer by day and a reader by night, he is loathe to discuss himself in the third person, but can be persuaded to do so from time to time.
RELATED ARTICLES

1 COMMENT

  1. WOW! My mind is swimming with numbers and letters! I just got done reading another article on G Code in here a few minutes ago so I’m seeing numbers and letters flashing in front of my eyes! haha. I still have a lot to learn! These articles help with that. But I’m afraid I’m going to dream about these G Codes and drive my self nuts tonight! lol

Most Popular

Recent Comments

mperkins37 on 3D Printed Rockets
desitheblonde on New Low-Cost LSAM 3D Printer
Mad3DHatter on Flex3Drive Review
Salvatore_Lacorte on Guide to Successful ABS Printing
Jordi Lopez on 3D Printer Maintenance
Bill Nonnenmacher on 3D Printed Gears Easy!
Andy Marriott on Flex3Drive Review
Denny Hannaford on Creality Ender 3 Announced
Tom Baxter on 3D Printer Maintenance
Daniel Faegnell on How does 3D Printing work?
Tom Baxter on 3D Printer Maintenance
Tom Baxter on 3D Printer Maintenance
Henry Jolly on 3D Printer Maintenance
mperkins37 on 3D Printer Maintenance
Brian Martin on 3D Printer Maintenance
Melanie F. on DIY etching
Melissa Englebright on 3D Printer Maintenance
Kelly Freeman on 3D Printer Maintenance
Jeremy Fister on 3D Printer Maintenance
Ronan on DIY etching
mperkins37 on 3D Printer Maintenance
mperkins37 on 3D Printer Maintenance
mperkins37 on 3D Printer Maintenance
Leesa R McClure on 3D Printer Maintenance
Charles Goldman on 3D Printer Maintenance
Tom Baxter on 3D Printer Maintenance
mperkins37 on 3D Printer Maintenance
Carol Oddy on DIY etching
Tom Baxter on 3D Printer Maintenance
Michael Perkins on 3D Printer Maintenance
Michael Perkins on 3D Printer Maintenance
Michael Perkins on 3D Printer Maintenance
Richard Bynum on 3D Printer Maintenance
Richard Bynum on Slicers: Which one to use?
Brian Martin on Flexion Retrofit Kit Review
Carol Oddy on DIY etching
Richard Bynum on Flexion Retrofit Kit Review
Michael Perkins on Flexion Retrofit Kit Review
Richard Bynum on 3d printer Extruders
Michael Perkins on DIY etching
Richard Bynum on Rigid.ink Review
Justin K Jones on Wanhao D7 Review
Brian Martin on Creality Ender 3 Announced
Michael Perkins on Creality Ender 3 Announced
Richard Bynum on Autodesk to .STL
Chris Kockler on Creality Ender 3 Announced
Michael Perkins on MG Chemicals wood filament
Ronald Shropshire on MG Chemicals wood filament
Michael Perkins on MG Chemicals wood filament
Richard Bynum on 3D printed CNC Mill
Richard Bynum on 10 Fun Things to 3D Print
Justin Flugum on Creality Ender 3 Announced
Richard Bynum on Creality Ender 3 Announced
Justin Flugum on Creality Ender 3 Announced
David Griffith Rowe on Interesting 3D Printed Drone Projects
Richard Bynum on Wanhao D7 Review
Richard Bynum on ColorFabb Filament Review
Richard Bynum on Who is 3D-PT?
Richard Bynum on BuildTak – Is it Worth it?
Richard Bynum on Who’s 3D model is it?
Sumit Trivedi on MG Chemicals wood filament
Richard Bynum on CAD Review for 3D Printers
Asgor Reidaa on DIY etching
Asgor Reidaa on Wanhao D7 Review
Richard Bynum on MG Chemicals wood filament
Richard Bynum on 3d Print a Rubber band gun
Richard Bynum on 3d Print a Rubber band gun
Justin Flugum on Wanhao D7 Review
Tom Baxter on Wanhao D7 Review
Asgor Reidaa on 3d Print a Rubber band gun
Nathan Cox on Wanhao D7 Review
Nathan Cox on DIY etching
Tom Baxter on DIY etching
Richard Bynum on DIY etching
George Fomitchev on DIY etching
Richard Bynum on Wanhao D7 Review
Richard Bynum on Magnetic PLA Filament
Justin Flugum on Selfcad – A Short Review
Justin Flugum on Top 10 3D Printer Upgrades
Stan Baldwin on Vacuum Drying PLA Pt.1
Richard Bynum on 3D Printed Robots & Figures
Richard Bynum on Marlin a beginners guide
Richard Bynum on G-Codes – Wiki
Richard Bynum on How to NOT Be a 3DHubs Noob
Richard Bynum on 3D-Printing for Scuba Diving
Richard Bynum on Vacuum Drying PLA Pt.2
Asgor Reidaa on 3D Printing Dictionary
Richard Bynum on Vacuum Drying PLA Pt.1
Richard Bynum on What 3D-Printer to buy 2016
Richard Bynum on 3D Printing Homes
Madalyn Nguyen on 3D Printing Dictionary
Daniel Waldner on Prusa i3 MK3 – New Features
Richard Bynum on TOP 5 3D PRINTED CARS
Richard Bynum on 3D Printer safety tips
Annaloa Hilmarsdottir on The Anet A8 3D-Printer DIY Kit Review
David Robert Pemberton on 3D Printed Grenade Launcher
Justin Flugum on 3D Printer safety tips
Darren Scrubb on 3D Printing in the Classroom
Tom Baxter on 3D Printable Tools
Darren Scrubb on 3D Printing Homes
Darren Scrubb on 3D Printing Jewellery
Richard Bynum on Flex3Drive Review
Stan Baldwin on 3D Printed Grenade Launcher
Richard Bynum on Magigoo Adhesive Pen
Linda Beghtel on 3D Printing Jewellery
Richard Bynum on How much to Charge?
Justin Flugum on How much to Charge?
Jon Gardner on Big 3D Printers
Tom Baxter on 3D Printing Dictionary
Richard Bynum on 3D Print Wood Working Tools.
Richard Bynum on Sienci Labs Mill One
Lori Mahan on 3D Printing Jewellery
Tom Baxter on RIP Pinshape 2013-2016
Richard Bynum on 3D Printing Dictionary
Justin Flugum on 3D Printable Tools
B Michenfelder on Sienci Labs Mill One
John Smith on 3D Printing Jewellery
Richard Bynum on 3D Printed Gears Easy!
Stephen Shimatzki on The 3D Printing Gifts Guide 2018
Richard Bynum on Helpful Holiday Safety PSA.
Santiago Archilla on Making Money With 3D Printing
Braxten Brannon on 3D Printing in the Classroom
Stuart Hawton on 3D Print Wood Working Tools.
Richard Bynum on 3D Printing Jewellery
Tom Baxter on 3D Printing Jewellery
Stuart Hawton on 3D Printing Jewellery
Stuart Hawton on 3D Printing in the Classroom
Richard Bynum on 6 Taboos of 3D Printing
Dawn Mateo De Acusta on Holiday Gifts for Your 3D Printer
Todd Whetstone on Folgertech FT-5 R2 – Review
Todd Whetstone on Folgertech FT-5 R2 – Review
Richard Bynum on 3D Printing Filament Review
Sandi McGinnis on Folgertech FT-5 R2 – Review
Andreas Gasser on Folgertech FT-5 R2 – Review
Edward Dekkers on Folgertech FT-5 R2 – Review
Andrew Venkersammy on Holiday Gifts for Your 3D Printer
Braxten Brannon on 10 Hotends for your 3D printer
Jon Acosto (3DPrintnerd.com) on Calidum HALE Heated Bed – Review
Macario on Flex3Drive Review
Tom Baxter on Beer based Filament
Tom Baxter on Rick and Morty 3D Models
Richard Bynum on Rick and Morty 3D Models
Richard Bynum on Top 10 3D Printer Upgrades
eduardo martini on Prusa i3 MK3 – New Features
Richard Bynum on Random Models on Thingiverse
Richard Bynum on Random Models on Thingiverse
Michael Champlin on Random Models on Thingiverse
Richard Bynum on Random Models on Thingiverse
Michael Champlin on How to calibrate a 3D Printer
Michael Champlin on 3D Printer safety tips
Richard Bynum on Selfcad – A Short Review
Richard Bynum on Selfcad – A Short Review
Richard Bynum on The Ultimaker 2 3D Printer
Jared Heifetz on Top 5 3D Printers Under $300
Jared Heifetz on Top 5 3D Printers Under $300
Richard Bynum on Top 5 3D Printers Under $300
Jared Heifetz on 3D Printer safety tips
Richard Bynum on 3D Printer safety tips
Jared Heifetz on Magigoo Adhesive Pen
Jon Acosto (3DPrintnerd.com) on The 13 Phases of 3D Printing
Jared Heifetz on 3D Printable Tools
Richard Bynum on 3D Printable Tools
Jared Heifetz on 3D Printable Tools
David Klein on 3D Printable Tools
Richard Bynum on 3D Printable Tools
mperkins37 on 3D Printable Tools
Jared Heifetz on 3D Printable Tools
mperkins37 on 3D Printable Tools
Dewu Han on 3D Printable Tools
mperkins37 on 3D Printable Tools
Tania Alam on 3D Printable Tools
Jon Acosto (3DPrintnerd.com) on Advertising Your 3D Printing Business
mperkins37 on Sienci Labs Mill One
mperkins37 on Flex3Drive Review
Jeffrey M. Holliman on Flex3Drive Review
tpoage@mindspring.com on The Ultimaker 2 3D Printer
tpoage@mindspring.com on Snapmaker: The All-Metal 3D Printer
tpoage@mindspring.com on The best 3d print bed material
tpoage@mindspring.com on Snapmaker: The All-Metal 3D Printer
Stan Baldwin on 3D Printed Grenade Launcher
tpoage@mindspring.com on 3D Printed Grenade Launcher
tpoage@mindspring.com on A New Era in Desktop 3D Printing
tpoage@mindspring.com on Dynamo3D One Pro Unboxing & First Print
tpoage@mindspring.com on 3D Printed Guns as Illegal 3D File?
tpoage@mindspring.com on 3D Printed Guns as Illegal 3D File?
tpoage@mindspring.com on Get more from your cyclops scanners
tpoage@mindspring.com on 5 kits to get more from your 3D Printer
mperkins37 on TOP 5 3D PRINTED CARS
tpoage@mindspring.com on Top 10 3D Printer Upgrades
tpoage@mindspring.com on Media falsely attacks 3d printing again
tpoage@mindspring.com on 3D Printing Communities on Google+
tpoage@mindspring.com on 3D Print Wood Working Tools.
mperkins37 on TOP 5 3D PRINTED CARS
tpoage@mindspring.com on 3D Printing Market Trends For 2017
mperkins37 on TOP 5 3D PRINTED CARS
tpoage@mindspring.com on 3d Printing Brushless Motors and More
tpoage@mindspring.com on TOP 5 3D PRINTED CARS
jvastine on TOP 5 3D PRINTED CARS
mperkins37 on TOP 5 3D PRINTED CARS
tpoage@mindspring.com on 3D Printer manufacturers list 2020
tpoage@mindspring.com on How Strong is PLA? Lab Experiment!
tpoage@mindspring.com on Vacuum Drying PLA Pt.2
tpoage@mindspring.com on Top 6 Unique CAD Programs (2016-2017)
tpoage@mindspring.com on Finishing & Painting A 3D Printed Alien!
tpoage@mindspring.com on 10 Popular 3D Printing Fidget Patterns
tpoage@mindspring.com on Slicers: Which one to use?
tpoage@mindspring.com on Top 10 Large Format 3D Printers
tpoage@mindspring.com on 13 Best CAD Programs for Kids
tpoage@mindspring.com on 10 Places To Get Free 3D-Printing Files
tpoage@mindspring.com on Upgrading a Prusa i3
tpoage@mindspring.com on Top 7 3D Scanners on a Low Budget
tpoage@mindspring.com on 5 Fun Prints for your new 3d printer.
tpoage@mindspring.com on The Tantillus Part 1
tpoage@mindspring.com on What is Love? 3D Print Me (NSFW)
tpoage@mindspring.com on 3D Printing for the Second Cold War Pt.1
tpoage@mindspring.com on 5 Ways to Feed your 3D Printing Habit
tpoage@mindspring.com on Helpful Holiday Safety PSA.
tpoage@mindspring.com on 3D Printing a Quadcopter: Part 1
mperkins37 on Testing TinkerCAD Beta
tpoage@mindspring.com on Will your 3D-printer kill you?
mperkins37 on Testing TinkerCAD Beta
tpoage@mindspring.com on Big 3D Printers
mperkins37 on Testing TinkerCAD Beta
tpoage@mindspring.com on Testing TinkerCAD Beta
mperkins37 on Testing TinkerCAD Beta
tpoage@mindspring.com on Nanodax Glass Wool Polypropylene Review
tpoage@mindspring.com on Kanesis Hemp Bio Plastic PLA Review
tpoage@mindspring.com on Great 3D-Printers to look for 2016!
choschiba on 3D Printing Fidgets
tpoage@mindspring.com on Folgertech Kossel build Part 1
tpoage@mindspring.com on Build Plate Supported 3D Printing
tpoage@mindspring.com on Top 6 Unique CAD Programs (2016-2017)
tpoage@mindspring.com on Let’s move our prints to the cloud!
tpoage@mindspring.com on The Guardian of Techno phobia
tpoage@mindspring.com on 3D printing your own cosmetics with Mink
tpoage@mindspring.com on 3D Printing Fidgets
tpoage@mindspring.com on Folgertech Kossel build Part 1
tpoage@mindspring.com on Build Plate Supported 3D Printing
tpoage@mindspring.com on Ultimaker 3 – A Quick Review
Nick Kalogeropoulos on Why 3D Printing Must Alter Its Course
Andrew Werby on 3D Printing Homes
Andrew Werby on 3D Printing Homes
Nick Kalogeropoulos on 3D Printing in the Army: Here’s how
mperkins37 on 3D Printing Homes
mperkins37 on 3D Printing Homes
juggernath on 3D Printing Homes
mudface2003 on Upgrading a Prusa i3
Alexis Puentes on Five amazing DIY 3d printers.
lucpet on 3D Printing Piracy
Tony Davies on 10 Fun Things to 3D Print
Italo Soares on 3D Printed Gears Easy!
Frostbite on Vacuum Drying PLA Pt.1
3AM Productions on 3D printer after care Package
3AM Productions on RIP Pinshape 2013-2016
Italo Soares on About me: Italo Soares
Lays Rodrigues on Slicers: Which one to use?
Robbie Pearson on How To Use TinkerCAD
Robbie Pearson on Edit STL Files with TinkerCAD
Tony Davies on Marlin a beginners guide
3AM Productions on 3D PRINTED SEX TOYS
Alexis Puentes on Sintron Prusa i3 Review
Daniel F on Beer based Filament
Curtis J. Pratt on Beer based Filament
bioelectrobot on Beer based Filament
admin on Makergear M2