G-code
G-code
Definition
G-code is a numerical control programming language — essentially a text file containing a series of “coordinate + action” instructions. In 3D printing, the slicer converts 3D model files (STL, OBJ, etc.) into G-code, and the printer’s controller reads and executes these instructions line by line to complete the print.
Simple Analogy
Imagine writing an extremely detailed navigation manual for a robot: “Move forward 10 cm, turn right 90 degrees, move forward 5 cm, stop, extrude some sauce…” G-code is exactly that instruction manual for the printer, except the coordinates are accurate to micrometers and the actions are timed to milliseconds.
Why It Matters
G-code is the bridge that connects “digital model” and “physical print.” Here are a few key G-code commands every 3D printing enthusiast should know:
| Command | Meaning |
|---|---|
G1 X10 Y20 E5 |
Linear move to (10, 20) while extruding 5 mm of filament |
G28 |
Home all axes |
G29 |
Run auto bed leveling |
M104 S200 |
Set nozzle temperature to 200°C |
M140 S60 |
Set bed temperature to 60°C |
G91 / G90 |
Switch to relative/absolute coordinate mode |
Practical Advice
Most regular users don’t need to and shouldn’t manually edit G-code — the slicer automatically generates optimal code. But knowing G-code can save you in these situations:
- Printer starts with nozzle in the wrong position: Check if
G28(homing) is included in the start G-code. - Nozzle stays on the model after printing: Add
G1 Z{layer_height+10}to the end G-code to raise the nozzle. - Need custom actions like filament change or pause: Insert the corresponding M-code in the slicer’s “Custom G-code” section.
We recommend starting your learning by reading the beginning of any .gcode file generated by your slicer — it contains all the startup procedures (heating, leveling, purging) in plain text. Reading through it once will show you exactly what your printer is doing after you hit “start print.”