G-code Basics: Understanding What Your Printer Actually Does
The Language Machines Speak
Every movement, temperature change, fan adjustment, and retraction that your 3D printer makes is the result of executing a G-code command. G-code is a text-based numerical control language developed in the 1950s for CNC machine tools and adopted, with modifications, by the 3D printing world. A slicer takes your 3D model and translates it into thousands of G-code commands that your printer executes in sequence. Understanding G-code — even at a basic level — gives you diagnostic capabilities and customisation options that most printer users never access.
G-code files are plain text — you can open one in any text editor and read it. If you've ever been curious what's in the file you send to your printer, open it. The commands are systematic and logical once you know the basic vocabulary.
The Essential Commands
G28 — Home all axes. Moves each axis to its home position (where the endstop triggers). G1 X100 Y100 Z50 E10 F3000 — Move to coordinates X100, Y100, Z50 whilst extruding 10mm of filament at 3000mm/min feedrate. Feedrate (F) is in mm/min, not mm/s — divide by 60 to convert. G92 E0 — Set the current extruder position to zero without moving. Used to reset the extrusion counter before a move. M104 S215 — Set hotend temperature to 215°C and continue without waiting. M109 S215 — Set hotend temperature to 215°C and wait until reached. M140 S60 — Set bed temperature. M190 S60 — Set bed temperature and wait. M106 S255 — Part cooling fan at 100% (255 = maximum on the 0–255 scale). M107 — Fan off.
Start and End G-code
Your slicer's "Start G-code" runs before the print begins and typically: homes the printer, heats the bed to temperature and waits, heats the hotend, does a purge line at the edge of the bed, and moves to print start position. The "End G-code" retracts the filament, cools the hotend, moves the print to a presentation position, and shuts down heaters. These are visible in your slicer's printer settings and can be customised. Understanding the commands means you can add a bed mesh probe command, change the purge line pattern, or add a filament presentation step after the print completes.
Using the Terminal for Diagnostics
Both OctoPrint and Klipper's web interfaces provide a terminal where you can send G-code commands manually. This is an invaluable diagnostic tool: manually extrude 10mm of filament to verify the extruder is working. Manually move the toolhead to check axis movement. Set temperature to verify the heater responds. Query the current temperature with M105. Test retraction distances for retraction calibration. Extrude 100mm at slow speed for e-step calibration. The terminal makes all of these procedures accessible without the need to print a calibration model for each test — direct, fast, and responsive. Combine with quality filament and systematic calibration for the best results.
Leave a comment
This site is protected by hCaptcha and the hCaptcha Privacy Policy and Terms of Service apply.