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 Dean McClements
Written by
 6 min read
Published October 24, 2022
Updated October 24, 2024

Learn more about g-code and when it is used in CNC machining.

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

G-code (geometric code) is the most common CNC (computer numerical control) programming language used to drive computer-controlled manufacturing machines. It is not a single computer language but rather a closely related group of high-level (and theoretically human-readable) languages that provide motor and relay/switch control instructions to machine functions such as: axis-traverse motors, spindle speed, and physical positions relative to an absolute or incremental datum. 

A CNC machining center is instructed by G-code commands to select from a variety of rotating cutters that remove material from highly specialized mechanical parts like crankshafts for internal combustion engines, for example. Additionally, G-code is the most common language used by additive manufacturing (3D printing) machines. In both cases, the process follows precise and repeatable paths that are each encoded as a series of motion instructions, positions, motor signals, and specialized machine commands.

Below are a few examples of G-code instructions: 

  1. G21: Sets the measurement base to metric, mm
  2. G0 X34: The tool moves +34 mm along the X-axis from the previous position at the maximum traversing speed. 
  3. G1 X34 F150: The tool moves +34 mm along the X-axis at a specified speed (150 mm/s). 

The code also commands such aspects as: geometric positions in which the cutter is to be placed, the required spindle speeds and tool changes, and the speed and route to be used on the approach to the part. Many G commands are modal, meaning that the computer will consider them binding until they’re superseded by another modal command of the same type. 

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.

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.

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 to Read G-code Commands

G-code is highly structured and easy to read at a high level. Even without knowing all the commands, a line of code can be understood in general terms. Each line of code is structured simply and consistently. For example:

G1 (move at specified speed) X60 Y30 Z80 (to these coordinates) F200 (at a  feed rate of 200 mm/s)

G0 (move as fast as possible) X0 Y0 Z0 (to the origin)

With a cheat sheet of G-codes and an understanding of the workspace’s coordinate system, the code becomes easy to read.

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

How It Works

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.

There are several types of G-codes that are divided into functional groups or subclasses. Some commands are modal, meaning they are valid until superseded by another modal command. Others are non-modal, so they specify an action that happens only once. The basic categories are as follows:

  1. Rapid positioning: G00
  2. Interpolation types: G01, G02, G03, G06
  3. Selection of the reference plane for follow-on commands: G17, G18, G19
  4. Tool offset: G40, G41, G42, G43, G44
  5. Zero offsets: G53 - G59
  6. Uni-directional position: G60
  7. Exact stop mode: G61
  8. Description of the process: G80 - G89
  9. Dimensions: G90, G91
  10. Feed rates: G93, G94, G95
  11. Spindle rotation speed: G96, G97
  12. Wait time: G04
  13. Increment or decrement speed: G08, G09
  14. Thread (inner and outer) specifications: G63
  15. Set Work Coordinate Systems Shift Value: G92

Editing G-Code

The best G-Code editor depends on the user’s needs. There are two very different audiences for the language: regular programmers and light users. Regular CNC tool programmers — people who can essentially think in G-code — generally need a zero-frills text editor type of interface, a visualization tool, and a few bulk action shortcuts. Light users like beginners and home users, by contrast, may need more hand-holding. Below are listed some of the best G-code editors for users on both ends of the spectrum:

  1. NCPlot: NCPlot is a minimalist text editor environment that includes great tools for editing G-code. It also has a neat toolkit to generate G-code from text and has time-estimation tools.
  2. TextPad: TextPad is a low-cost but capable software with many of the tools needed for more expensive applications. It is basically a G-code-empowered version of Windows Notepad, but with some important differences including the ability to directly import and merge groups of G-code into a single file and the capability of coloring groups of code.
  3. G-Wizard Editor: G-Wizard Editor uses a very approachable method based on visual editing. This software, from CNCCookbook, is a collection of powerful tools and advisory information. The basic method is called “conversational G-code” and operates using high-level commands like "face mill the part," automatically generating a block of G-code for this action. It also has an error-checking algorithm that guards against faults such as cutters crashing into the part during traverse stages.

How Xometry Can Help

Xometry provides a wide range of manufacturing capabilities, including CNC machining and other value-added services for all of your prototyping and production needs. Request a free, no-obligation quote.

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 Dean McClements
Dean McClements
Dean McClements is a B.Eng Honors graduate in Mechanical Engineering with over two decades of experience in the manufacturing industry. His professional journey includes significant roles at leading companies such as Caterpillar, Autodesk, Collins Aerospace, and Hyster-Yale, where he developed a deep understanding of engineering processes and innovations.

Read more articles by Dean McClements

Quick Links

  • Home

  • Contact Us

  • Help Center

  • About Us

  • Careers

  • Press

  • Investors

  • Xometry Go Green

Support

  • Privacy Policy | Terms of Use | Legal

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


© 2024 Xometry, All Rights Reserved