G-code is the set of instructions that tells your 3D printer exactly how to print a model.
When you slice a 3D model in software like Cura, PrusaSlicer, or Bambu Studio, the slicer converts the model into G-code. The G-code gives the printer detailed commands like:
Where to move (X, Y, Z coordinates)
How fast to move (print speeds)
When to start or stop the extruder (turning filament flow on or off)
How much filament to push (extrusion amounts)
Temperatures for the hot end and heated bed
Fan speeds for cooling
Special commands like auto bed leveling, filament changes, or pauses
In short:
G-code is the language your printer reads to physically create the part, layer by layer.
G-code originally comes from the 1950s and 1960s, developed for automated machine tools like mills and lathes during the early days of numerical control (NC).
It became more standardized in 1979 when the Electronic Industries Alliance (EIA) published RS-274, the official G-code standard.
1950s — Early concepts of numerical control (NC) are developed for automated machine tools.
1958 — John T. Parsons and MIT develop the first computer-controlled milling machine.
1960s — G-code evolves informally as manufacturers create early programming methods for NC machines.
1979 — The Electronic Industries Alliance (EIA) publishes RS-274, the first standardized version of G-code.
1980s–1990s — CNC technology spreads across industries, using G-code as the primary programming language.
2000s — 3D printing emerges for industrial use and quickly adopts G-code as its control language.
Today — G-code remains the backbone for 3D printers, CNC routers, laser cutters, and other digital fabrication tools.
Test and Calibrate First:
Always start by running test prints and fine-tuning your G-code, especially when changing filament types or printing settings. G-code commands like G29 (auto-bed leveling) help ensure better print adhesion and accuracy.
Adjust Flow Rate:
In some cases, you may need to adjust the extrusion flow rate in your G-code. M221 S100 sets the flow rate to 100%. Lowering the percentage helps if your print is over-extruding, and increasing it can help with under-extrusion.
Temperature Adjustments:
You can fine-tune the extruder and bed temperatures directly within the G-code. For example, M104 S220 sets the hot end to 220°C for high-temperature filaments like ABS.
Speed Control:
G1 F{speed} can control print head speed. Lower speeds are ideal for intricate prints, while higher speeds are used for large, simple objects. Always experiment to balance speed and quality.
Retraction Settings:
For reducing stringing, use commands like G1 E-1 (retract 1mm of filament). This prevents excessive filament from oozing while the nozzle is moving between print areas.
Keep the Nozzle Clean:
If you notice inconsistent extrusion, your nozzle might be clogged. Use M104 S0 (turn off hot end temperature) before clearing the nozzle. You can also increase retraction to reduce nozzle buildup.
End G-Code Sequence:
It's good practice to add an end sequence to your G-code to ensure a clean stop:
M104 S0 – Turn off the hot end.
M140 S0 – Turn off the heated bed.
M107 – Turn off the cooling fan.
G28 X0 Y0 – Home X and Y axes.
M84 – Disable motors.
Basic Movement Command:
G1 X50 Y50 Z0.3 F1500
Explanation: Moves the print head to X=50, Y=50, Z=0.3 at a feed rate (speed) of 1500 mm/min.
Extruding Filament:
G1 E10 F200
Explanation: Extrudes 10 mm of filament at a feed rate of 200 mm/min.
Home All Axes:
G28
Explanation: Homes all axes (X, Y, Z), bringing the print head and bed to their home positions.
Set Temperature for Hot End:
M104 S210
Explanation: Sets the hot end (extruder) temperature to 210°C.
Set Temperature for Heated Bed:
M140 S60
Explanation: Sets the heated bed to 60°C.
Disable Motors:
M84
Explanation: Turns off stepper motors to release tension on the axes.
Start a Print:
G21 – Set units to millimeters.
G90 – Set to absolute positioning (every position is relative to the origin).
M107 – Ensure the fan is off.
G92 E0 – Reset extruder position.
G1 F1500 E30 – Start extruding filament.
Pause a Print:
M25
Explanation: Pauses the print at the current location.
Below you'll find some very helpful G-Code videos and links. This will give you a better understanding about G-Code and how to write it.