[Guide] GCODE – List of most used and useful commands

More often we hear about Gcode and the need to change it according to personal preferences. Gcode is a real language and allows us to make our CNC machine do anything. We can change the welcome message, insert a melody, until we conceptually change the movements. The interface that allows you to create Gcodes suitable for our 3d printers are special software called Slicer.
Many times in this blog we have talked about slicers, particular programs designed to transform a model into machine language, the GCODE. These software create the paths that the nozzle will have to make and determine how much material to deposit, in total autonomy, to form the finished object.


It is true that human intervention and intelligence can be useful in finding the best position in which a given object should be printed to minimize the supports or possible errors, as well as it is decisive for various settings, depending on the type of material in use or other factors that the machine can not know.
Once this is done, however, the software proceeds autonomously to form the GCODE, that is, the set of movements combined with extrusion that are performed in the order and with the perfect times, typical of electronic brains, that create our object, exactly as it was thought and designed.

What do we need to know about Gcode commands then? If the software does everything by itself, why should we intervene and communicate with the machine?
The answer to these questions, which anyone will have asked themselves at this point, is one and simple: Customization.

We know that each machine is different, as components, project and software, (of course I’m talking about different models and brands, equal machines will behave in the same way) and as different will have different defects.
To get to correct these defects or simply if we want our machine to perform certain operations at the beginning or at the end of a print we could impose it by adding the commands of the GCODE.
For example, for a lower power consumption we could tell our machine to turn off the nozzle, the plate and the motors at the end of the job, in this way we could not be present at the end of the print, but we could also introduce ourselves a few hours later knowing that we have not “paid” that time. Or, if we had a probe for the levelling of the plate we could decide to level the plate to the probe before each print, to be sure of an excellent result.

These changes can be made in 2 ways:

1 – Through the slicer. Each slicer has a special space where to insert the head and tail Gcode. Once we have found this space, we just need to add the lines of code corresponding to the commands we want to give and the machine will automatically complete them in each print. An example of a rather common start and end Gcode is the following:


  •  G28 X0 Y0 Z0 – Home all axes
  • M107 – Turns off the layer fan if it is on
  • G1 F200 E3 – Extrudes a small amount of filament to ensure that the wire is loaded


  • G28 X0 Y0 – Return to zero in x and y
  • M104 S0 – Extruder power off
  • M140 S0 – Flat switch-off
  • G1 E1 F200 – Portrays a little filament
  • M84 – Turn off engines

2- As a second method, less orthodox than the first, we can have our favorite slicer process the gcode and then open the file with the notepad. Through the notepad we will see all the commands and we can intervene adding or removing commands at will. With this method you can also intervene in the heart of the processing, inserting pauses or any other high command to meet our needs. Obviously going to touch a gcode is not easy and if you are not an expert you risk to have more damage than benefits.

Having said this as promised here is the list of Gcode commands, a kind of dictionary Man-Machine-Machine-Man. As for the languages it will not be enough to know the words but you will have to compose real phrases, you will have to follow the correct order of the commands if you want to be understood by your interlocutor: the machine.




G0 Quick Movement
example: G0 X11 rapid movement in X=11mm.

G1 Controlled movement X Y Z E
example: G1 X80 Y10 E10 moves from the current position (X0,Y0) to (80,10) and extrudes 10mm of material.

G2 Arc-controlled clockwise movement
example: G2 X80 Y10 I5 J10 E10 goes from the current position (X,Y) with hourly arc movement to the position (80,10) keeping a constant distance from the point (5 10) extruding the material from the current position until the arrival extruding 10 mm of material.

G3 Arc-controlled counterclockwise movement
example: same as the previous command but the arc movement is counterclockwise

G4 Pause for S or P
example: G4 P200 do nothing for 200 msec. Inserts a pause of the number of milliseconds indicated. During this time the machine maintains the parameters but remains stationary.

G10 Retracts the filament according to the specifications of the M207 command.

G11 Retracts and recovers the filament according to the specifications of the M208 command

G28 Returns to the point of origin of the axes

G29 Command for testing the print surface. Use a three-point test.

G30 Command for testing the printbed. Use only one test point

G31 Returns the current test status.

G32 Z head and calculates the position of the Z plane

G90 Use absolute coordinates

G91 Use relative coordinates

G92 Set coordinates
example: allows programming of absolute zero, to reset the current position to the specified values. No physical movement will occur. Without any specification, the command will reset all axes to zero.

M Basic GCode

M0 Stop.
Example: M0 – The machine stops and returns to its rest position, then switches off. All motors and heaters turn off. To restart the printer, press Reset.

M1 Sleep.
Example: M1 – The machine stops and returns to its rest position, then switches off. All motors and heaters are switched off. The machine restarts by pressing any key.

M104 Sets the temperature of the selected extruder
Example: M104 S190 sets extruder temperature to 190°C

M105 Reads the current temperature from the sensor

M106 Fan on

M107 Fan off

M108 Sets the extrusion speed

M109 Sets the extrusion temperature and waits for the extruder to cool down.

M110 Sets the current G-code line

M114 Displays current position

M115 Displays current firmware version

M Advanced GCode

M17 Turns all stepper motors on or off

M18 Turns off stepper motors such as the M84 control

M20 Shows the contents of the SD card

M21 Initializes the SD card

M22 Removes the SD card from the memory card.

M23 Select a file from SD

M24 Starts or resumes printing an SD file.

M25 Pause of printing from SD

M26 Sets the position of the SD in bytes

M27 Returns the print status of the SD file

M28 Start writing to SD

M29 Ends writing to SD

M30 Deletes a file from the SD card

M41 Loop printing

M42 Change pin status via gcode

M80 Turns on the power supply

M81 Turns off the power supply

M82 Selects absolute codes of extruder E (default)

M83 Selects the relative codes of the E-Etrusor

M84 Disable stepper motors until the next movement, or use S to specify a waiting time before motors are disabled. S0 is used to disable the wait time.

M85 Sets the shutdown timer using the S parameter. To disable it set to zero (default)

M92 Sets the programming of the steps for the axes (To be used for calibration)

M114 Sends the current position to the serial port

M115 Communicates the current version of the firmware and the capacity of the microcontroller used

M117 Displays a message
Example: M117 “Printer Name”: Displays the printer name on the LCD.

M119 Notifies the serial port that an endstop status is present.

M140 Sets the temperature of the printing surface

M190 Waits until the temperature of the printing surface reaches the set temperature

M200 Sets the diameter of the filament

M201 Sets maximum print acceleration in units/second square for movements during printing (M201 X1000 Y1000)

M202 Sets the maximum acceleration in unit/square second for non-print movements (M202 X1000 Y1000). This command is not used in Marlin firmware.

M203 Sets the maximum extrusion speed of the machine (M203 X200 Y200 Z300 E10000) in mm/sec.

M204 Sets the default speed: S for normal movements; T only for material dispenser movements (M204 S3000 T7000) in “mm/sec square” in mini time segments, expressed in ms (B20000)

M205 Advanced settings: minimum movement speed S=during printing T=only movements, B=minimum time segment X=maximum tear xy, Z=maximum tear Z , E=maximum tear E

M206 Sets an additional rest point

M207 Sets the retraction length S[positive mm] F[feedrate mm/sec] Z[additional zlift/hop]

M208 Sets the maximum movement for the axes

M209 Enables automatic retraction

M220 Sets the value of the speed override factor in percent

M221 Sets the value of the extrusion override factor in percent

M240 Trigger pulse for taking a picture

M300 S(xxxx) P(xxxx). The M300 basically tells the printer: “sing!”. The S is the height of the sound and the P is the duration in milliseconds.

M301 Sets the parameters PID, P I and D

M302 Enables cold extrusion

M303 PID relay autotune S sets the temperature (default = 150C)

M400 Finishes all movements

M500 Stores parameters in the EEPROM

M501 Reads parameters from EEPROM

M502 Returns to factory settings. Of course these must have been stored in the EEPROM previously.

M503 Prints current settings (from memory and not from eeprom)

M999 Restart after an error

These are the main commands that we will use on our printers.
If I’ve forgotten some and/or if you have some gcode start or end to recommend add it in the comments!


If you have found this post useful, please LIKE on Easy 3D Home Facebook’s page to receive updates on all the news of the Blog! You can find other guides about 3D in our Guides section!

Leave a Reply

%d bloggers like this: