Anyone familiar with the world of 3D printing knows how much work can go into a printed model! Above all, one thing lies behind it: G-code!
In this article, you will learn everything you need to know about G-code commands, G-code files, G-code readers, and the differences from M-code.
This basic knowledge is the perfect foundation, especially for beginners, to further their education on the subject of 3D printer G-code.
What is G-code?
In short, G-code is a set of instructions for a 3D printer. The 3D printer requires G-code commands that it can execute, because without them, it knows neither where nor how to print.
Models for 3D prints are usually exported as STL files and are also predominantly available in this format. With the help of slicer programs, this format can be converted into a G-code file and used.
The origin of G-code
G-codes were developed in the industrial sector in the 1950s for milling machines and lathes. They have been used there ever since. With the advent of 3D printing, G-code was also adopted in this field, as geometric movement patterns can also be encoded, which can then be printed with the 3D printer.
How G-code works
G-code is a sequence of commands that the 3D printer can read and execute. The printer reads the G-code from top to bottom and executes all commands one after the other. Accordingly, the order of the commands is important.
How do you read G-code?
Basically, there is one G-code command per line in a G-code file. This is composed of the command and its parameters.
An example would be the command G1. This means that the print head should move in a straight line. Following this command are the parameters for the target position (X;Y;Z), speed (F), and filament extrusion (E). There are X and Y coordinates that indicate the direction on the surface and the Z coordinate that describes the height (layer). With the help of a G-code reader or viewer, you can precisely identify and read the G-code commands.
The structure of a G-code file
A G-code file does not always have the same structure and can be built differently depending on the model. Basically, there are three blocks.
The start area, also called initialization, includes:
- Homing (finding the zero point)
- Setting temperatures
- Preparing the print bed
- Configuring fans
The main part, which describes the printing process, includes the following aspects:
- Movement commands (G0 / G1)
- Extrusion (E-values)
- Layer change (Z-movement)
- Speed changes
The conclusion completes the printing process and includes the following points:
- Moving the print head away
- Turning off the heater
- Deactivating motors
G-code vs. M-code
G-code and M-code are fundamentally different.
G-code: Movement and geometry
M-code: Machine states and functions
Both are essential commands for the 3D printer and must be combined to be able to print a model. Thus, the tasks of G-code are moving the axes, driving lines and curves, and controlling positions.
The M-code sets the temperature, turns the fan on/off, controls the extruder, and operates the motor.
Common G-code commands
Here you will find essential and frequently used G-code commands in different categories.
Movement commands
G00: Rapid movement (travel move)
Example: G00 X150 Y150 moves the nozzle quickly to the coordinates X150, Y150.
G01: Controlled linear movement
Example: G01 X200 Y200 F1800 E22 moves with a feed rate of 1800 mm/min to X200, Y200 while extruding 22 mm³ of filament.
G28: Automatic homing (origin search) The nozzle and the print bed move to their end-stop positions (X=0, Y=0, Z=0) to establish a reference point for printing.
G28 is included first in almost every G-code file, as it allows the nozzle and print bed to be moved to their starting position.
G90/G91: Positioning mode
Defines the coordinate system.
G90: Absolute positioning (default). The coordinates tell the machine the exact position (e.g., “Move to X=10”).
G91: Relative positioning. The coordinates tell the machine the distance to move (e.g., “Move 10 mm to the right from your current position”).
Temperature commands
M104/M109: Set extruder temperature (hotend)
Example: M104 S200 sets the hotend to 200 °C. (The printer does not wait for the temperature to be reached before it begins printing.)
Example: M109 S210 heats to 210 °C and maintains the temperature until the program is ready.
M140/M190: Set bed temperature
Example:
M140 S60: Sets the print bed to 60 °C (without waiting).
M190 S60: Sets the print bed to 60 °C and waits until it is heated.
Cooling commands
M106: Fan on
Example: M106 S127 turns the fan on at half speed (127 corresponds to 50% of the maximum value of 255). M106 S255 turns the fan on at full speed.
M107: Fan off
Turns the fan off.
In the image below, there is an example of a G-code file with frequently used G-code commands.

How can G-code be edited or optimized?
A G-code file can be edited or optimized. There are two ways: editing via a G-code editor and direct text editing. The following sections explain the details of each approach.
Slicer software
A safe method to adjust print settings is to use slicers. Starting from the original STL file, all parameters such as speed, temperature, or support structures can be set there. A new G-code is then generated. Afterward, the new G-code file should be checked in a G-code viewer, G-code reader, or G-code simulator so that any errors can be detected.

Edit the text directly
Editing G-code text is only recommended for those with good coding knowledge. This approach is not advised for beginners, as small errors in the G-code can cause major printing errors. Directly editing the G-code file requires sound knowledge and precision to ensure no errors occur. Here, too, it is recommended to check the G-code for errors using a G-code simulator or G-code viewer.
Conclusion
G-code is the language of the 3D printer. Most 3D printing models are available as STL files and must be converted into a G-code file so that they are readable for the 3D printer. A file consists of various commands that are executed by the 3D printer in the appropriate order. G-code commands can be edited and optimized in a G-code file. If you are a beginner, it is recommended to use a G-code editor or a slicer, as direct text editing can cause serious errors. With the help of G-code viewers and G-code simulators, you can check for errors in the G-code before printing or determine if the print can be started without further editing.