The Xometry app works best with JavaScript enabled!
  • Solutions
  • Industries
  • Resources
  • Enterprise
  • How Xometry Works
  • Become a Supplier
ResourcesMachining DesignGet to Know G-Code

Get to Know G-Code

picture of Kat de Naoum
Written by
Rebecca Piccoli headshot
Updated by
 4 min read
Published October 24, 2022
Updated January 3, 2025

Everything you need to know about the unsung hero of modern manufacturing

Worker operating a CNC machine with a g-code monitor. Image Credit: Shutterstock.com/Quality Stock Arts

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.

Types of 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 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:

How to read G-code
How to read G-code

Frequently Asked Questions on G-Code

Is it considered 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.

What’s the best code editor?

This depends on your experience and needs. Regular programmers who practically think in G-code will prefer a no-nonsense text editor where they can get right to it. A more casual user will benefit but also enjoy a program that’s easier and simpler to use. Some examples of editors that we believe kind of fit in the middle of the spectrum are NCPlot (minimalist with great tools for editing and generating code), TextPad (not very expensive and has features for importing, merging, and color-coding G-code), and G-Wizard Editor (user-friendly visual editor with error-checking and even conversational G-code features that let you tell it what you want and it will generate the code for you).

What’s 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.

picture of Kat de Naoum
Kat de Naoum
Kat de Naoum is a writer, author, editor, and content specialist from the UK with 20+ years of writing experience. Kat has experience writing for a variety of manufacturing and technical organizations and loves the world of engineering. Alongside writing, Kat was a paralegal for almost 10 years, seven of which were in ship finance. She has written for many publications, both print and online. Kat has a BA in English literature and philosophy, and an MA in creative writing from Kingston University.

Read more articles by Kat de Naoum

Quick Links

  • Home

  • Contact Us

  • Help Center

  • About Us

  • Careers

  • Press

  • Investors

  • Xometry Go Green

Support

  • +1-800-983-1959

    support@xometry.com

Mailing Address

  • Privacy Policy | Terms of Use | Legal

  • ITAR | ISO 9001:2015 | AS9100D | ISO 13485:2016 | IATF 16949:2016


© 2025 Xometry, All Rights Reserved