This code is a huge deal in today’s manufacturing. It acts as the universal translator between human instructions and the precise movements of machines. It’s used for almost everything, from shaping metal into individual parts to guiding 3D printers through how to build designs. In this article, we’ll look at G-code a little closer and learn some examples of different codes.
What is G-Code?
An abbreviation for Geometric Code, this is by far the most common set of instructions that controls the brains of CNC (computer numerical control) machines. In theory, it’s readable by humans, and it gives instructions on a number of things like axis-traverse motors, spindle speeds, and setting positions based on reference points, whether they’re fixed or changing. It also tells the machines which tools to choose at any given time and just generally controls everything until the CNC machine or 3D printer has completed the job. Here are some examples of code:
- G21: This sets the measurement base to metric, mm.
- G0 X34: The tool will move +34 mm along the X-axis from its previous position at its maximum speed.
- G1 X34 F150: The tool will move +34 mm along the X-axis again, but this time at a specific speed, which in this case is 150 mm/s.
Many commands are modal, which means that the computer will stick to them until they’re replaced by another command of the same type. The beauty of G-code is that it pushes the machine to get to work without the need for constant supervision. Some specific examples of CNC machines that use it are 3-axis mills, 4- or 5-axis machining centers, lathes, jig bores and drills, and electrical discharge machining or other wire-cutting equipment.
For G-code to work, it uses a coordinate system (sometimes like a grid, and other times circular) so programmers can define the actions to give the machine. The controller in the machine will then translate that information into electrical signals to operate the various parts of the equipment (motors, pumps, etc). So technically, the machine controls itself, but the code tells it exactly what to do and when to do it.
The first-ever G-code was developed at the MIT Servomechanisms Laboratory in 1958. Since then, different manufacturers have continued to develop the code, sometimes making it specific to their own equipment. In 1980, however, the Electronic Industries Alliance adopted and standardized the version that was made at MIT and formalized it as the RS-274-D, which is the basis for what we use today.
What Is the Function of G-Code?
G-code is intended to tell machines what to do or how to move. It codifies a 3D reasoning process, guiding cutters, print heads, etc. through a path that positions them for the intended task and executes the command. Along the way, G-code specifies spindle speeds and coolant flows and controls any necessary tool changes. The language allows CNC programmers (or other computer-based machiners) to write cut-and-move sequences that create detailed procedures that their machines can follow without supervision.
Where Is G-Code Being Used?
G-codes are most often used in the programming of complex computer-aided manufacturing machines such as: CNC 3-axis mills, CNC 4- or 5-axis machining centers, CNC lathes, CNC jig borers and drills, and electrical discharge machining or other wire-cutting machining centers. It is also very common in 3D printing operations of all types.
When Was G-Code First Used?
The first G-code was created in 1958 at the MIT Servomechanisms Laboratory. Subsequent versions have been developed by various machine and controller manufacturers, generally using variations on the G-code standard, each tailored to the developers’ own equipment. The standard version was adopted by the Electronic Industries Alliance shortly after its development at MIT in 1980 and eventually became the current, standardized RS-274-D language.
How Does G-Code Work?
G-code specifies a series of points and line-by-line instructions that are programmed into a CNC machine. It operates in an orthogonal (or occasionally polar) coordinate environment so that a programmer can write traversing movements, spindle speeds, cutting motions, and coolant commands. The commands are converted, within the machine controller, to control signals for parts such as motors and pumps. An instruction to, for example, move along a clockwise arc between two coordinates at a set speed must be converted to electrical signals that drive motors. A G-code, therefore, does not act as a direct machine control signal but instead provides instructions to a controller integrated into the machine. Much like machine code programming, high-level G-code commands are converted into a form of machine language for execution.
How Does G-Code Control Machine Tools?
G-code can control machine tools by sending instructions to the CNC machine controller on a line-by-line basis. The controller is integrated into the machine functions which control the motors and drives that move the machine parts such as: drive motors, spindles, and coolant pumps. The machine control module is responsible for executing the programmed motions according to its G-code instructions.
What Are the Types of G-Code?
In addition to the modal commands we mentioned earlier, G-code also includes some non-modal instructions that demand an action that only happens once. There are several categories of this code, and the basic ones are as follows:
- Rapid positions: G00
- Interpolation types: G01, G02, G03, G06
- Selection of the reference plane for follow-on commands: G17, G18, G19
- Tool offset: G40, G41, G42, G43, G44
- Zero offsets: G53–G59
- Uni-directional position: G60
- Exact stop mode: G61
- Description of the process: G80–G89
- Dimensions: G90, G91
- Feed rates: G93, G94, G95
- Spindle rotation speed: G96, G97
- Wait time: G04
- Increment or decrement speed: G08, G09
- Thread (inner and outer) specs: G63
- Set work coordinate systems shift value: G92
How to Read G-code Commands
Although quite advanced, G-code is not too difficult to read, even without knowing every single command. Every line is consistent and structured nicely. For instance:
G1 (move at specific speed) X60 Y30 Z80 (to these coordinates) F200 (at a feed rate of 200mm/s)
G0 (move as quickly as possible) X0 Y0 Z0 (back to origin)
If you have a cheat sheet and a general understanding of the coordinate system of your workspace, it becomes relatively easy, so don’t worry. The following image shows the general breakdown of the code:

Frequently Asked Questions on G-Code
Is G-Code a Programming Language?
Absolutely, in a very raw and real way. When you think of programming anyway, it’s usually made up of highly structured sequential instructions that, when followed by a machine’s processor, will achieve some kind of virtual or real-world outcome. That’s also what G-code is, in a nutshell.
Is G-code used on All CNC Machines?
Yes, G-code is used on all CNC machines. It is a tool for translating design intent into cutter action.
What Is the Difference Between G-Code and M-Code?
They’re both sets of commands that control CNC machines, but they differ slightly in their purposes. Unlike G-code, which controls the movement of the machine, maps out the area to avoid any obstacles as the tools move, and manages other machine functions, M-code handles more specific actions like turning the coolant on or off, changing tools, or controlling features that are only native to certain machines. Basically, G-code is universal, and M-code is tailored to each machine which makes it specific to the manufacturer.
How Xometry Can Help
If you need any help with your G-code or have questions related to manufacturing, you can reach out to one of our representatives who can assist you. Xometry also offers a wide range of related services, like CNC machining, 3D printing, and laser cutting. You can start your project right away by requesting a free, no-obligation quote right from our website.
Disclaimer
The content appearing on this webpage is for informational purposes only. Xometry makes no representation or warranty of any kind, be it expressed or implied, as to the accuracy, completeness, or validity of the information. Any performance parameters, geometric tolerances, specific design features, quality and types of materials, or processes should not be inferred to represent what will be delivered by third-party suppliers or manufacturers through Xometry’s network. Buyers seeking quotes for parts are responsible for defining the specific requirements for those parts. Please refer to our terms and conditions for more information.
