The Ultimate Guide to G-Code for 3D Printing

If you’ve ever fired up your 3D printer and watched it spring to life, you may have wondered: How does it know what to do? The answer is G-code. This is the magical language that tells your printer how to move, how hot to get, how fast to extrude filament, and much more. But don’t worry, G-code isn’t a foreign language – once you understand it, you’ll be controlling your printer like a seasoned pro.

This guide will walk you through every G-code command you’ll need to know for 3D printing. By the end, you’ll have the power to manipulate your 3D prints with precision and confidence. Ready to become a G-code wizard? Let’s dive in!


What Exactly Is G-Code?

Before we dive into the G-code commands, let’s first break down what it actually is. Think of G-code as a list of instructions for your 3D printer, similar to a recipe. It tells your printer where to go, how to extrude filament, and how hot things should get.

G-code is used to control every aspect of the printing process, from moving the print head to adjusting temperatures and speeds. The good news? G-code isn’t hard to understand once you know the basics. And as you get more comfortable with it, you’ll realize just how much control you have over the printing process!


Movement Commands: The Print Head’s Roadmap

These commands are all about getting the print head to the right spot. They tell your printer how to move around and where to extrude filament.

G0 – Rapid Positioning (No Extrusion)

  • What it does: Moves the print head to a specified position quickly without extruding filament.
  • When to use it: Travel moves between parts of the print where no filament is needed.

G1 – Linear Interpolation (Controlled Movement with Extrusion)

  • What it does: Moves the print head while extruding filament at a specified feed rate.
  • When to use it: The main movement command when printing – it’s what makes your print come to life!

G2 – Clockwise Circular Interpolation

  • What it does: Moves the print head along a clockwise arc or circle.
  • When to use it: For circular or curved patterns in your print.

G3 – Counterclockwise Circular Interpolation

  • What it does: Moves the print head along a counterclockwise arc or circle.
  • When to use it: Similar to G2, but for counterclockwise curves.

G28 – Auto Home

  • What it does: Sends the print head to the home position (usually the endstops or limits of each axis).
  • When to use it: At the start of a print or if you need to reset the printer so said printer knows where it is..

G29 – Auto Bed Leveling

  • What it does: Measures the bed’s height at multiple points and adjusts accordingly to ensure proper adhesion.
  • When to use it: When you want to ensure a level bed for perfect prints, especially if the bed isn’t flat.
  • About G29- Bed leveling tends to have the printer conduct a 3×3 or 5×5 levelling routine, meaning how many probes are done in the x and y axis. Assuming you have a leveling probe such as a BLTouch, you can manually direct the probe to conduct a max of 50×50 probes. The more probes done, the better your bed will be levelled when printing.

G30 – Probe Z Position

  • What it does: Probes the bed and measures the height of the Z-axis.
  • When to use it: Often used in automatic bed leveling sequences.

G92 – Set Position

  • What it does: Sets the current position of the print head to a specified coordinate.
  • When to use it: If you need to reset the zero position of your printer or after a tool change.
  • Variables G92- Command to set position/ X? Y? Z?- Set X, Y, Z position where ? is any number between 0 and the max XYZ values for your 3D printer.

Temperature Control: Keeping Your Printer Hot (Or Cool)

Temperature is crucial in 3D printing. The hotend (nozzle) needs to reach the correct temperature to extrude filament, and the heated bed needs to be hot enough to help the print stick. These G-codes manage that process.

M104 – Set Hotend Temperature

  • What it does: Sets the hotend (nozzle) to a specific temperature without waiting. Meaning it will heat up the hotend while continuing its printing actions.
  • When to use it: Right before printing to heat the nozzle.
  • Variables- M104 S? – Where ? is any number from 0 to whatever the max temperature is for your hot end. Be aware that if you don’t have an all metal hotend to limit the max/ target temperature to no more than 260*C.

M109 – Set Hotend Temperature and Wait

  • What it does: Sets the hotend to the desired temperature and waits until it’s reached before proceeding.
  • When to use it: When you want to ensure the hotend has reached the target temperature before starting the print.
  • Variables – M109 S? Where ? is the target temperature the printer will wait until it achieves if its heating up. R? is another variable where ? is the temp the printer will pause printing until it reaches the number even if its cooling. T? R! the last variable where T is the extruder, ? is the extruder number assuming you have multiple extruders and R (you can alternatively use S) has already been discussed.
  • Example: M109 T3 R210

M140 – Set Bed Temperature

  • What it does: Sets the bed to the specified temperature.
  • When to use it: To set the bed to the right temperature for adhesion.
  • Variable: M140 S? Where ? is the temperature the bed is set to achieve. Will set temperature while continuing to print.
  • Example: M140 S111

M190 – Wait for Bed Temperature

  • What it does: Waits for the bed to reach the specified temperature before continuing the print.
  • When to use it: At the start of a print to make sure the bed is heated before printing.
  • Variables: M190 R?/S? T!(Optional) Where ? (Note that you can use R or S, but not both simultaneously) is the temperature the printer will pause printing until it achieves that value whether its heating or cooling for R, and in variable S case, the temp the printer must achieve only when heating in order to continue printing. T is optional and tell the printer how many seconds to pause to allow the print bed to cool.

M106 – Fan On

  • What it does: Turns the cooling fan on.
  • When to use it: To cool the printed layers, which is especially important for overhangs and fine details.

M107 – Fan Off

  • What it does: Turns the cooling fan off.
  • When to use it: To turn off the fan when it’s not needed.

Extruder Control: Feed Me, Seymour!

Extruder control is all about how much filament gets pushed through the nozzle. If the extruder is too fast or too slow, your print might suffer. These G-codes control how much filament is extruded and when.

M82 – Set Extruder to Absolute Mode

  • What it does: Sets the extruder to use absolute coordinates for extrusion. This means the printer will extrude a specific amount of filament from the zero point.
  • When to use it: To ensure that all extrusion values are referenced from the origin point.

M83 – Set Extruder to Relative Mode

  • What it does: Sets the extruder to relative coordinates. This means the printer will extrude based on the last position it was in.
  • When to use it: When you want to extrude filament relative to where the extruder last moved.

Pause, Stop, and Control: Take a Break (Or Not)

Sometimes you need to pause your print, change filament, or stop the print altogether. These commands give you the power to control exactly when and how your print pauses or stops.

M0 – Program Stop

  • What it does: Pauses the print at a specified point and gives you the option to intervene.
  • When to use it: If you need to change filament, adjust settings, or just take a break.

M1 – Optional Stop

  • What it does: Similar to M0, but it’s an optional stop. The printer will pause but can continue automatically if no intervention occurs.
  • When to use it: If you want to pause for an optional intervention, but don’t need to stop entirely.

M25 – Pause Print

  • What it does: Pauses the print at a specific point.
  • When to use it: For planned pauses (e.g., filament change or manual inspection).

G4 – Dwell (Pause for a Specific Time)

  • What it does: Pauses for a specified amount of time, allowing for cooldown or adjustments.
  • When to use it: After certain moves or before starting a new layer.
  • Variables: G4- Pause command/ P- Time in milliseconds/ S- Time in seconds
  • Example: G4 S200: Pause for 200 seconds/ G4 P5000: Pause for 5000 milliseconds

Other Commands to Know: Fine-Tuning Your Print

These are some other miscellaneous commands that control your printer in various ways. While they’re not used as frequently, they’re important to know when you start fine-tuning your print.

G17 – Select XY Plane

  • What it does: Selects the XY plane for circular interpolation and other operations.
  • When to use it: For operations that require two-dimensional motion.

G18 – Select ZX Plane

  • What it does: Selects the ZX plane.
  • When to use it: For operations that require two-dimensional motion in the ZX plane.

G19 – Select YZ Plane

  • What it does: Selects the YZ plane.
  • When to use it: For operations that require two-dimensional motion in the YZ plane.

G20 – Set Units to Inches

  • What it does: Switches the measurement units to inches.
  • When to use it: If you prefer working in inches instead of millimeters.

G21 – Set Units to Millimeters

  • What it does: Switches the measurement units to millimeters (the most common unit in 3D printing).
  • When to use it: For metric-based movements and measurements.

Miscellaneous Commands

M300 – Turn buzzer on

  • What it does: Turns the buzzer on
  • When to use it: Can be used as an alert so the system can alert you when there is an anomalous situation or as the G-Code proceeds from one section to another
  • Variables: M300 P? S!/ Where ? is the duration in milliseconds and ! is frequency

M300 S P


Conclusion: G-Code is Your 3D Printing Superpower

There you have it – every important G-code command you’ll encounter in the world of 3D printing! With this knowledge, you’ll be able to control your printer in ways you never thought possible. From controlling movement and temperature to pausing prints and tweaking extrusion, G-code lets you customize your 3D printing experience like a true pro.

Remember, 3D printing is both an art and a science. The more you experiment with these commands, the better you’ll understand how to fine-tune your prints for flawless results. Whether you’re printing a delicate prototype or a functional part, mastering G-code will give you the ultimate control over the process.

So go ahead, get your hands dirty in the G-code, and happy printing!


And that’s your deep dive into G-code for 3D printing! With this information in hand, you’re ready to start manipulating your G-code and making your prints even more amazing.