
G-code Basics: Understanding What Your Printer Actually Does
Danielle A.
The Language Machines Speak
Every movement your printer makes is controlled through G-code. Every travel move, extrusion line, temperature change, fan adjustment, retraction, and homing sequence comes from a long list of text based instructions generated by your slicer. G-code itself predates 3D printing by decades. It was originally developed in the 1950s for CNC machining equipment and eventually became the standard language used across manufacturing machinery. Modern 3D printers still rely on the same core idea: the slicer converts a 3D model into thousands of individual commands, and the printer simply executes them one after another.
For most people, G-code stays hidden in the background. But even a basic understanding of how it works opens up a huge amount of diagnostic and customisation potential. Once you understand what the commands are doing, troubleshooting becomes far less mysterious because you can start thinking about the printer in terms of instructions rather than just “something went wrong". One of the easiest ways to start learning is simply opening a G-code file in a text editor. They are plain text files, completely readable, and surprisingly logical once you recognise the structure.
The Essential Commands
Some G-code commands appear constantly across almost every print file.
G28 — Home All Axes
- This command tells the printer to home itself by moving each axis toward its endstop or sensor until the machine establishes a known starting position.
- Most printers run G28 at the beginning of every print before any movement or calibration takes place.
G1 — Controlled Movement
Commands like:G1 X100 Y100 Z50 E10 F3000
Tell the printer to move to a specific position while optionally extruding filament.
In this example:
- X100 Y100 Z50 defines the destination coordinates
- E10 tells the extruder to push 10 mm of filament
- F3000 sets the movement speed
One detail that surprises many beginners is that feed rate values are usually written in mm/min rather than mm/s. Divide by 60 to convert them into the speeds most slicers display.
G92 — Reset Position Values
G92 E0
This command resets the printer’s understanding of its current extruder position without physically moving anything.
It is commonly used to reset extrusion calculations before printing or retraction sequences.
Temperature Commands
Some of the most important commands control heating behaviour.
M104 S215
Sets the hotend temperature to 215°C but immediately continues executing the next command without waiting.
M109 S215
Sets the hotend temperature and waits until the target temperature is reached before continuing.
The same distinction exists for heated beds:
-
M140sets bed temperature without waiting -
M190sets bed temperature and waits
This process is why printers often begin heating the bed and nozzle before the print actually starts moving.
Fan Commands
M106 S255
Turns the part cooling fan on at full speed.
M107
Turns the fan off completely.
The fan speed scale runs from 0 to 255, with 255 representing 100% power.
Start and End G-code
Every slicer contains configurable “Start G-code” and “End G-code” sections that run automatically before and after printing.
Start G-code usually handles the following:
- homing the printer
- heating the bed
- heating the nozzle
- probing or bed levelling
- purge lines
- positioning the toolhead
End G-code typically:
- retracts filament
- cools heaters
- moves the print forward for removal
- disables motors and fans
Most users never touch these sections, but understanding the commands gives you much more control over how your printer behaves. You can add automatic bed mesh probing, customise purge lines, create filament unloading routines, or even move finished prints into presentation positions depending on the firmware your machine supports.
Using the Terminal for Diagnostics
One of the most useful features in OctoPrint, Klipper, and many printer web interfaces is the ability to manually send G-code commands directly to the machine through a terminal.
This turns the printer into something you can test interactively rather than only through full print jobs.
For example, you can:
- manually extrude filament to verify the extruder works correctly
- move axes independently to check motion systems
- test heaters and temperature response
- verify fan operation
- test retraction distances
- run extrusion checks for e-step calibration
- query live temperatures using
M105
This kind of direct control makes troubleshooting dramatically faster because you can isolate individual systems without repeatedly slicing and printing full calibration models. Once you become comfortable reading and sending basic G-code, printers start feeling far less like sealed appliances and much more like controllable machines. That understanding becomes incredibly valuable as you move into advanced calibration, firmware tuning, and custom workflows.

Leave a comment
This site is protected by hCaptcha and the hCaptcha Privacy Policy and Terms of Service apply.