Skip to content

G-code

The machine instruction language that tells the 3D printer where to move, how fast, and how much filament to extrude.

Theory

G-code (Geometric Code) is a numerical control programming language derived from CNC machining. Each line contains a command letter (G for motion, M for machine functions), coordinates (X, Y, Z), and parameters (E for extrusion, F for feedrate). Key commands: G1 (linear move), G28 (home axes), M104 (set nozzle temperature), M140 (set bed temperature). Firmware (Marlin, Klipper, RepRapFirmware) interprets and executes these commands in real time.

Application

Slicers generate G-code automatically. To customise, add start/end G-code scripts in slicer settings for custom homing, purge lines, and temperature tweaks. Use a G-code viewer (e.g. built into PrusaSlicer) to inspect toolpaths before printing. For multi-material prints, tool-change commands (T0, T1) switch active nozzles.

Common mistakes

Editing raw G-code requires knowing the specific firmware dialect: Marlin and Klipper differ in some commands. Incorrect start G-code can crash the nozzle into the bed before homing. Temperature wait commands (M109 vs M104) differ in blocking/non-blocking behaviour: M109 waits for target temperature, M104 does not. Never run G-code files intended for a different printer without review.

Related terms: Slicing, Flow Rate, Print Speed

Field3D printing, engineering
Also calledG code, toolpath code
SourceEDi Brain: tech/fdm

Engineer, author of The Big Book of 3D Printing and additive manufacturing expert