G-code (often written gcode) is the plain-text language that tells a 3D printer what to do. Each line is one instruction, such as heat the nozzle, move to a coordinate or push out a set amount of filament. Your slicer writes the file; the printer reads it line by line.
This guide explains what G-code is, what a few common lines mean, and when you actually need to read or edit it. The facts come from Marlin and Klipper documentation and Wikipedia, not from our own printing.
What is gcode? G-code in 3D printing explained
G-code in 3D printing is a list of text commands that a printer's firmware runs in order. Wikipedia traces the language back to numerical control work at the MIT Servomechanisms Laboratory in the 1950s. The first standardized US version, RS-274, was published by the Electronic Industries Association in 1963, and ISO 6983 was finalized in 1982. The name is short for "geometric code". For how this looks in PrusaSlicer's printer profile, see PrusaSlicer start G-code.
3D printers borrowed the idea from CNC machines. Your model does not go to the printer as a shape. A slicer cuts it into layers and converts each layer into thousands of small movement and extrusion commands. Our guide to what a slicer is covers that step, and STL vs 3MF vs G-code explains how the file types differ.
What does a line of G-code look like?
A typical line is a letter and number for the command, followed by parameters. Marlin's documentation describes G1 as a linear move: X, Y and Z give the target coordinates, E gives the extruder position and F sets the feedrate in units per minute. Coordinates are in millimeters by default.
So a line that starts with G1 and carries X, Y and E values means "move in a straight line to this point while feeding this much filament". A G1 line with no E value is a travel move that does not extrude. Marlin notes that G0 is an alias for G1 on Cartesian and delta machines, and by convention G0 is used for moves that do not extrude.
Which G-code commands do you see most often?
A few commands appear in almost every file. The meanings below come from Marlin's G-code index and command pages; Klipper's documentation lists the same core set as supported.
| Command | What it does |
|---|---|
G28 | Homes axes. With no parameters Marlin homes all axes; G28 X Z homes only X and Z. |
G0 / G1 | Linear move, with optional extrusion (E) and feedrate (F). |
G90 / G91 | Absolute or relative coordinates. G91 makes coordinates relative. |
G92 | Changes the recorded position of an axis without moving it. |
M104 | Sets the hotend target temperature and carries on. |
M109 | Sets the hotend temperature and waits until it is reached. |
M140 / M190 | Sets the bed temperature; M190 waits for it. |
M82 / M83 | Absolute or relative extruder positioning. |
M106 / M107 | Fan on and off (listed in Klipper's supported set). |
G4 | Dwell: pause for P milliseconds (Klipper's supported list). |
M400 | Wait for current moves to finish (Klipper's supported list). |
M220 / M221 | Speed and extrusion-flow override percentages; M220 S80 runs moves at 80% speed (Marlin). |
M112 | Emergency stop (Klipper's supported list). |
The pattern of M104 and M109 is worth knowing: the "wait" version stops the file until the temperature is reached, which is why start sequences usually heat the bed and nozzle before the first move.
How do you read a short run of G-code?
Marlin's G0/G1 page shows a three-line pattern that appears in almost every print file. Read it top to bottom:
G1 F1500
G92 E0
G1 X50 Y25.3 E22.4
- G1 F1500 sets the feedrate to 1500 mm/min, which is 25 mm/s. Feedrate is in units per minute, so slicer speeds in mm/s are multiplied by 60 inside the file.
- G92 E0 declares the extruder position to be zero without moving anything. Marlin describes G92 as setting the current position to the values given, so this resets the filament counter.
- G1 X50 Y25.3 E22.4 moves to X 50 and Y 25.3 while feeding 22.4 mm of filament. Marlin says the extrusion accelerates with the X and Y motion so all axes stay synchronized, provided the machine can reach the requested speed.
Two modes change how numbers are read. G91 makes every coordinate an offset from the previous position, and M83 makes each E value add to the previous extruder position. A file that looks wrong in a text editor is often just in relative mode; check the nearest G90, G91, M82 or M83 above the line. Klipper adds a wrinkle: M83 applies even in G90 mode, and M82 only cancels that forced mode without forcing absolute extruder coordinates.
Two more practical points. Hand-sent M220 S80 slows a running print to 80% without re-slicing, which is a quick way to test whether speed is the problem. And G92 will not let you move below the bed: since Marlin 1.1.0 the software endstops keep the physical limits, so it cannot be used to shift coordinates outside the machine's boundaries.
How does a printer use a G-code file?
The slicer writes the file in this order: a start section, then every layer, then an end section. The start section typically homes the printer, heats the bed and nozzle and primes the nozzle. The layer sections hold the long run of G1 moves. The end section turns heaters off and parks the head. Slicer settings such as layer height, speed and retraction all end up as numbers inside these lines. See layer height explained for how one setting changes the Z moves, and retraction settings for the filament pull-backs you may spot between travel moves.
The file is sent to the printer by SD card, USB or network, depending on the machine. Firmware then reads it and plans the moves. Marlin explains that each move is added to a planner and runs after earlier moves finish, following acceleration and jerk limits, so a long straight line is not simply run at the F value from the first millimeter.
Is G-code the same on every printer?
No. The core commands are widely shared, but firmware differs. Wikipedia says machine makers have added their own extensions to G-code, so operators must learn each vendor's differences. The same is true in 3D printing. Klipper says it aims to support the G-code that common slicers produce in standard configurations, not every possible command, and it adds its own extended commands such as SAVE_CONFIG and RESTART that use readable names. Less common Marlin commands such as G29 or M42 can be provided through a gcode_macro section. Read what Klipper is for the wider picture.
The practical rule: pick the right printer profile in your slicer, because it sets the start and end sections and the flavor of G-code for that firmware. A file sliced for the wrong printer may use commands the firmware does not understand.
Do you need to read or edit G-code?
Most people never need to. Change settings in the slicer and re-slice instead of editing the file, because the slicer keeps every line consistent. Reading it helps when something odd happens at the start of a print, because the start section is where heating and homing commands live.
Editing is reasonable for small, well understood changes, such as adding a command to the start section or inserting a pause at a layer. If you edit by hand, keep a copy of the original, change one thing at a time and watch the first print of the changed file closely. Do not change temperature or heating commands unless you know the printer's limits; follow the maker's guidance for safe temperature ranges.
If you want to see what a file will do without printing it, a previewer in your slicer draws the toolpath from the G-code. It is a good way to check seams, travel moves and supports. For how speed values affect results, see print speed vs quality, and for bed probing commands see auto bed leveling explained.
Can you write G-code by hand?
Yes. G-code is plain text, so any text editor can open it, and printers accept hand-written commands through a terminal in Klipper-based interfaces or other host software. Beginners usually do this to send a single command, such as homing with G28 or setting a temperature with M104. Writing a whole print by hand is possible only for very simple shapes, which is why slicers exist.
Related: Getting G-code onto the printer.




