Software
What is G-code and how to read the file your 3D printer prints
Your printer has no idea what an STL is. What it reads is a text file with thousands of very simple orders, one per line: “move here”, “heat the nozzle to this”, “push this much filament”. That language is G-code, and although the slicer writes it for you, understanding a bit of it helps you troubleshoot, tweak how every print starts and know what the machine is doing at any moment.
From model to printer
There are three steps. The model (an STL, OBJ or 3MF) describes the part's shape and nothing else. The slicer (Bambu Studio, OrcaSlicer, PrusaSlicer, Cura…) cuts it into layers and works out, for your printer and your filament, every path the toolhead will follow. The result is the G-code: concrete instructions that no longer work on another machine. If you're unsure about the slicer, we compare them in which slicer to use; and if your file is in another format, our 3D file converter turns it into STL or 3MF without uploading it anywhere.
The language comes from numerically controlled machines (mills and lathes), which have used it for decades. 3D printers adopted it with their own commands for things a mill doesn't have, such as temperatures or an extruder.
What a line of G-code looks like
Every line starts with a command: a letter (G for motion and geometry, M for machine functions) followed by a number. Then come the parameters, each a letter and a value. Everything after a semicolon is a comment the printer ignores; slicers use them a lot to mark layers and line types.
For example, G1 X60 Y20 E1.33 F1800 reads: linear move (G1) to X=60 mm, Y=20 mm, pushing 1.33 mm of filament (E) at 1800 mm per minute (F). Marlin's documentation explains that F is measured in units per minute and stays set for the following moves: 1800 mm/min is 30 mm/s.
Blue: travel · Orange: extruding move · Green: millimetres of filament
The commands you'll see in almost every file
There are hundreds, but a typical file relies on a dozen. Here they are, with the description Marlin's documentation gives them; Klipper accepts the same ones so slicer files work the same way:
| Command | What it does |
|---|---|
| G0 / G1 | Linear move. By convention, G0 for travel without extrusion and G1 for moves that extrude. |
| G28 | Auto home: each axis seeks its endstop or sensor. |
| G29 | Bed levelling: probes the surface and builds the compensation mesh (in Marlin). |
| G90 / G91 | Absolute or relative positioning. |
| M82 / M83 | Absolute or relative extrusion. |
| G92 | Set the current position without moving (often used as G92 E0 to zero the extruder). |
| M104 / M109 | Nozzle temperature: M104 sets it and carries on; M109 sets it and waits until it's reached. |
| M140 / M190 | The same for the bed: set, or set and wait. |
| M106 / M107 | Turn the part fan on at a speed (S0-255) or off. |
| M220 / M221 | Speed and flow percentage (what you change on the screen mid-print). |
| M600 | Filament change: pauses, retracts and waits for you to load another one (in Marlin). |
| M84 | Disable the motors, usually at the end. |
The difference between M104 and M109 explains something everyone has seen: the printer heats the bed, then “sits there” heating the nozzle, and only then starts. That's the start G-code waiting with M190 and M109.
Where the E number comes from
E is the most interesting part, because it's where the slicer does the maths. To draw a line, the printer has to lay down a volume of plastic: line width × layer height × length. That volume comes from pushing filament, which is a cylinder, so E is that volume divided by the filament's cross-section.
With the example's numbers: a line 0.4 mm wide and 0.2 mm tall along 40 mm is 0.4 × 0.2 × 40 = 3.2 mm³. A 1.75 mm filament has a cross-section of π × 0.875² ≈ 2.405 mm². So you need to push 3.2 ÷ 2.405 ≈ 1.33 mm of filament. That's the E1.33 on each side of the square. (Slicers refine this a bit, because a real line's cross-section isn't a perfect rectangle, but that's the idea.)
Two practical things follow. If your filament's real diameter isn't what the slicer thinks, every E is off and the part ends up under- or over-extruded: that's what flow calibration fixes, explained in input shaping, pressure advance and flow. And speed has a physical limit: more mm/s means more mm³ per second the hotend has to melt, as we cover in what is a hotend.
Absolute or relative: G90, G91, M82 and M83
In absolute mode (G90), X60 means “go to position 60”; in relative mode (G91), “move 60 from where you are”. The extruder has its own switch: with M82 E is a counter that keeps growing through the print (which is why G92 E0 shows up now and then, to reset it), and with M83 each E is what gets pushed in that move, as in our example.
Klipper's documentation adds a nuance: M83 forces relative extrusion even if everything else is absolute, and M82 only removes that forcing. This matters if you edit the start G-code by hand: mix modes up and the extruder can try to push tens of millimetres in one go.
Start and end G-code
Every slicer has, in the printer settings, two blocks of G-code it adds before and after the part. The start block usually heats the bed and nozzle, homes the axes, levels or loads the bed mesh and draws a purge line along the edge so the plastic comes out clean. The end block retracts a little filament, moves the toolhead away, turns off the heaters and fan and disables the motors.
It's the part people edit by hand the most: moving the purge line, adding a wait so the bed settles, or bringing the bed forward when the print finishes. If you edit it, keep a copy of the original and change one thing at a time.
Marlin, Klipper and others: same language, different dialects
Firmware is the printer's program that interprets G-code. Marlin does everything on the printer's board; Klipper shares the work with a more powerful computer and, besides the standard commands (the ones in the table), adds its own long-named commands such as BED_MESH_CALIBRATE for the bed mesh or EXCLUDE_OBJECT to cancel one part without stopping the rest, and lets you create macros. That's why, on Klipper printers, the start G-code is sometimes a single line calling a macro. We explain it in what is Klipper.
It isn't always a .gcode
Some brands package G-code in other formats:
- .bgcode (Prusa): binary G-code. According to Prusa, it cuts the size by about 70% on average; the MINI, MK4 and XL read it from firmware 5.1.0, and PrusaSlicer can convert it to text and back under “File › Convert”.
- .gcode.3mf (Bambu Lab): Bambu Studio exports the sliced result inside a 3MF file that carries each plate's G-code along with its data. Note: saving the project isn't the same as exporting the sliced plate.
Do you need to learn G-code?
To print, no: the slicer writes it for you. But skimming it helps with three very specific things: knowing what the printer is doing when it seems stuck, inserting a pause or a colour change at a layer (step by step in how to print multiple colours without an AMS) and tweaking the start G-code without fear. With the table above you already understand most of any file.
Frequently asked questions
- What's the difference between an STL and a G-code file?
- An STL describes the part's shape (a mesh of triangles) and works for any printer. G-code is the specific set of instructions for one printer and one material: where to move, how fast, how much filament to push and at what temperature. The slicer turns the first into the second.
- Can I use someone else's G-code?
- Only if you have the same printer and the same material, and even then carefully: it carries the temperatures, bed size and start G-code of the machine it was sliced for. The safe route is to download the model (STL or 3MF) and slice it yourself.
- What does F mean in G-code?
- It's the movement speed (feedrate). In Marlin it's expressed in units per minute, so F1800 is 1800 mm/min, or 30 mm/s. It stays in force for the following moves until another line changes it.
- How do I add a pause to change colour?
- The easiest way is to ask the slicer, which inserts the command at the layer you choose. In Marlin, the filament change command is M600. We walk through it in how to print multiple colours without an AMS.