What is a G-Code and What is its Use in 3D Printing?

Published on September 23, 2021 by Madeleine P.

As we know, additive manufacturing goes far beyond simply turning on the machine and pushing a button. There are many steps behind this process, from the design of a part to its final post-processing, and all the steps in-between. One of these important steps before starting to 3D print is that it is necessary for the model in question to go through a cutting software, also called slicers. In these programs, what happens is that an STL design file is converted into a control file for the 3D printer. This file is composed of the so-called G-Code, a programming language that allows the machine to understand what commands it must follow to manufacture the final part. But what is this digital language and how important is it in the manufacturing process?

The G-Code consists of G and M commands, each with an assigned motion or action. The combination of these commands will allow the 3D printer to understand which pattern to follow in order to create the final part. As we have said, this is a language automatically generated by the cutting software when converting the design into an STL file. In this case we will focus only on FDM 3D printers, so we will refer to terms such as extruder, print tray, or thermoplastic filaments. Among the different types of commands that the 3D printer will interpret, we find commands for movement, extrusion, heating and detection in a sequence. This is the basis for understanding the importance of this language, however, let us now see the numerical composition of a G-Code to be able to read the command in question.


The G-Code language is automatically generated by the slicer (photo credits: Ultimaker Cura)

What is a G-Code made up of?

First we must understand the difference between a G-Code and an M-Code. Both are commands included in the file and tell the printer how and where to extrude the material. The only difference is that G-Codes are universally understood by printers using G-Codes, and M-Codes are those codes that are specific to individual printer lines. So, as we can see in the picture below, the language is made up of several parameters. The basic things to know when reading such a code are the different alphanumeric values.

The letters X / Y / Z refer to the three axes of the 3D printer that mark the coordinates. Any value of X above 0 moves the printhead to the right, any value of Y above 0 moves the printhead backwards, and any value of Z above 0 moves the printhead upwards. On the other hand, the letter F is understood as the speed at which the nozzle moves (indicated in mm/minute), while the letter E refers to the length of the movement (indicated in millimeters). Sometimes we can find text followed by the symbol “;” which serves to provide command information; these comments are not part of the code. Having understood how G-Codes can be read, let’s see which are the most common for the manufacture of a part.


Examples of commands for 3D printing

The G1 command is the most basic of all, in fact, it will make up 95% of the total file. It is a code that instructs the 3D printer to perform a linear motion while depositing material to the specified location at the coordinates that are given to it. So, when we read the code “G1 X10 Y20 F1200” we will be instructing the printer to move to the X=10mm Y=20mm position in the tray at a slower speed of 1200 mm/min. Unlike this command, the G0 has the same principle of movement, but without extruding material through the nozzle.

G28. This command is used for the machine to execute the start sequence, which will move the printhead to the far edges of the machine until it makes contact with the stops. If no axis is specified, the machine will automatically move all three, but you can always add X, Y, Z to the command. This is a useful way to quickly move an axis out of the way, especially when finishing the print.

G92. Instructs the printer to set the current position of its axes. This can be useful if you want to change or offset the location of one of the axes. This is usually done at the beginning of each layer or just before a main or retract command.

M104. This code is used to heat an extruder, and you must indicate which one (in case you have a double extrusion 3D printer), as well as the desired temperature. Thus, the command “M104 S200 T0” will order the machine to heat the extruder T0 (in the case of double extrusion, we would have T0 and T1) to a temperature of 200 degrees Celsius, indicated with the letter “S”. The other version of this G-Code, namely M109, will instruct the printer to wait for the extruder to reach the temperature before continuing with any other command.

M140 and M190. They are very similar to those already mentioned, except that in this case it does not refer to the extruder, but to the printing bed. In this case the letter “T” indicating the extruder to be heated is omitted.

FDM 3D printers have 3 axes (X, Y, Z) that allow them to be positioned in the printing coordinates

Final recommendations

The list of G-Codes and M-Codes that we can find is really extensive. In fact, there are more than 1000 different commands that can tell the 3D printer what to do at any given moment. That is why this language is automatically generated by the slicer prior to the manufacturing process. Knowing the basics of the codes can be useful and interesting for some users. However, let’s not forget that writing your own G-Code is complicated and can even damage your 3D printer. Unless you are very clear about what you want to edit from the final file, we do not recommend that users generate the part coding themselves. Still, we encourage you to continue to get to know and learn about how these advanced solutions work, the different commands available, as well as the system used in a technology of this caliber.

What do you think of the use of G-Codes in 3D Printing? Let us know in a comment below or on our Facebook and Twitter pages. Don’t forget to sign up for our free weekly newsletter, with all the latest news in 3D printing delivered straight to your inbox!

Share Your Thoughts

Your email address will not be published. Required fields are marked *

Stay Updated
Every wednesday, receive a recap of the latest 3D printing news straight to your inbox.