The Xometry app works best with JavaScript enabled!
ResourcesMachining DesignG-Code: Definition, Function, and Different Types

G-Code: Definition, Function, and Different Types

Megan Conniff - Xometry Contributor
Written by
 11 min read
Published October 24, 2022
Updated February 10, 2026

Geometric Code (G-code) is a language used to control CNC machines and 3D printers. G-code consists of a set of instructions that guide the machine in performing specific tasks (moving along particular paths, adjusting speeds, and managing tool changes). The tool translates human input into precise machine actions, ensuring accuracy in manufacturing processes. G-code is necessary for a wide range of applications, from shaping metal parts in manufacturing to guiding the layer-by-layer construction of 3D printed objects.

The function of G-code is to provide clear, sequenced instructions that allow machines to perform complex operations autonomously. G-code directs movements along specific axes, sets spindle speeds, controls coolant systems, and adjusts other critical machine parameters. The code enables the machine to carry out detailed tasks with high precision, reducing the need for manual intervention and increasing efficiency in production.

G-code commands are categorized based on their specific function, each serving a precise purpose in controlling machine movements, tool changes, and other operations. G0 is used for rapid positioning, G1 for linear interpolation, and G2/G3 for clockwise or counterclockwise circular interpolation. G4 introduces a dwell time, while G20 and G21 control the measurement system (inches or millimeters). G-code commands control tool offsets, coordinate system shifts, and specific machining cycles (drilling and tapping). The wide range of G-code commands allows CNC machines and 3D printers to perform diverse operations with precision and repeatability.

What is G-Code?

Geometric Code (G-code) is the standard set of instructions that controls the operation of CNC (computer numerical control) machines. G-code is used to govern various actions (the movement of motors, spindle speeds, and setting positions) based on reference points. G-code is used to determine tool changes and manage the entire process until a CNC machine or 3D printer completes a task. The code is theoretically human-readable, which means that operators and programmers are able to interpret it. For example, the command ‘G21’ sets the measurement system to metric, specifically millimeters. The command ‘G0 X34’ instructs the tool to move 34 mm along the X-axis at maximum speed. A command ‘G1 X34 F150’ directs the tool to move 34 mm along the X-axis at a speed of 150 mm/min. The commands are modal, meaning the commands remain in effect until another command of the same type replaces them. The feature minimizes the need for continuous monitoring, allowing the machine to operate autonomously.

The G-code system relies on a coordinate system (Cartesian, aka grid-based, or polar, aka circular), which allows programmers to define precise movements and actions. The CNC machine’s controller translates the instructions into electrical signals, which control the motors, pumps, and other components of the machine. The machine is responsible for executing the tasks, while G-code specifies the precise steps and timing. The first version of G-code was developed by various manufacturers in 1958 at the MIT Servomechanisms Laboratory. The Electronic Industries Alliance standardized the G-code developed at MIT in 1980, adopting it as RS-274-D. The standardized G-code forms the foundation for modern CNC machines, including 3-axis mills, lathes, electrical discharge machines, and 3D printers, all relying on it for precise control of operations.

What Is the Function of G-Code?

The function of G-code is to instruct machines on how to perform specific tasks, guiding cutters, print heads, and other components through precise movements. G-code defines the path for positioning the parts and executing the intended task. It controls parameters (spindle speeds, coolant flows, and tool changes) when necessary. The language allows CNC programmers to create detailed sequences that direct machines to complete complex tasks autonomously, without supervision.

Where Is G-Code Being Used?

G-code is used in the programming of complex computer-aided manufacturing machines. 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 are included. G-code is used in 3D printing operations across various types of printers (FDM desktop printers used for prototyping and functional parts).

When Was G-Code First Used?

G-code was used in 1958 at the MIT Servomechanisms Laboratory. Machine and controller manufacturers developed their own versions of G-code, adapting the standard to suit their equipment (industrial CNC milling machines produced by different manufacturers). The Electronic Industries Alliance adopted the standardized version developed at MIT in 1980, which became the RS-274-D language, the foundation of modern G-code.

How Does G-Code Work?

G-code works by specifying a series of points and line-by-line instructions programmed into a CNC machine. G-code operates in a Cartesian (aka grid-based) or occasionally polar (aka circular) coordinate environment, allowing programmers to write movements, spindle speeds, cutting motions, and coolant commands. The machine controller converts commands into control signals that operate components (motors and pumps). For example, an instruction to move along a clockwise arc between two coordinates at a set speed is translated into electrical signals that drive the motors. G-code does not directly control the machine but provides instructions to a controller integrated into the machine. G-code commands are converted into machine-level instructions for execution, such as step and direction signals.

How Does G-Code Control Machine Tools?

G-code controls machine tools by sending line-by-line instructions to the CNC machine controller. The controller, integrated into the machine, directs the motors and drives that move parts of a CNC machine (drive motors, spindles, and coolant pumps). The machine control module executes the programmed motions according to the G-code instructions, ensuring precise and accurate operation of the machine tools.

What Are the Types of G-Code?

The types of G-code are listed below.

  • Rapid positions (G00): Directs the machine to move rapidly between points without regard for path accuracy.
  • Interpolation types (G01, G02, G03, G06): Defines linear interpolation (G01), circular clockwise (G02), circular counterclockwise (G03), and spline interpolation (G06).
  • Selection of the reference plane for follow-on commands (G17, G18, G19): Specifies the plane for circular interpolation, G17 (XY plane), G18 (XZ plane), G19 (YZ plane).
  • Tool offset (G40, G41, G42, G43, G44): Controls tool radius compensation, G40 (cancel), G41 (left compensation), G42 (right compensation), G43 (tool length compensation positive), G44 (tool length compensation negative).
  • Zero offsets (G53–G59): Sets machine zero offsets and local coordinate systems.
  • Uni-directional position (G60): Restricts the tool movement to a single direction, improving accuracy.
  • Exact stop mode (G61): Forces the machine to stop exactly at each programmed position for precise control.
  • Description of the process (G80-G89): Defines various machining cycles, G80 (cancel canned cycle), G81 (drilling cycle), G82 (drilling with dwell), G83 (peck drilling), G84 (tapping cycle), G85 (boring cycle), G86 (boring with spindle stop), G87 (back boring), G88 (boring with manual retraction), G89 (boring with dwell).
  • Dimensions (G90, G91): Defines the mode for programming dimensions, G90 (absolute positioning), G91 (incremental positioning).
  • Feed rates (G93, G94, G95): Controls feed rate modes, G93 (inverse time), G94 (feed per minute), G95 (feed per revolution).
  • Spindle rotation speed (G96, G97): Adjusts spindle speed for constant surface speed (G96), and G97 resets it to a fixed RPM.
  • Wait time (G04): Inserts a dwell or pause in the program for a set period.
  • Increment or decrement speed (G08, G09):  Modifies feed rate incrementally (G08) or performs precise motion (G09).
  • Thread (inner and outer) specs (G63): Defines the tapping cycle for internal threads.
  • Set work coordinate systems shift value (G92): Specifies the workpiece coordinate system shift.

How to Read G-code Commands

To Read G-code command, follow the 5 steps below.

  1. Understand the structure. Recognize that each line of G-code is consistent and follows a structured format, making it easier to interpret.
  2. Interpret movement commands. Identify G1 as the movement command for a specific speed, followed by coordinates (X60 Y30 Z80), with F200 indicating the feed rate of 200 mm/min.
  3. Recognize rapid movement. Identify G0 as the command to move at the machine's maximum traverse speed to the specified coordinates, such as X0 Y0 Z0.
  4. Refer to the cheat sheet. Use a cheat sheet to decode commands and understand the coordinate system in the workspace.
  5. Familiarize with the coordinate system. Know the layout of the machine’s coordinate system to interpret movements and tool paths accurately.

The following image shows the general breakdown of the code:

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

How does a CNC Machine Read G Code Files?

A CNC machine reads G-code files by first loading the file into its controller. The controller interprets each line of the code, which contains instructions for specific movements, speeds, and tool changes. The instructions are converted into electrical signals that drive the motors, spindles, and other machine components. The controller processes the G-code instructions in real-time, converting them into electrical signals that control the machine's movements, speeds, and tool operations. It enables precise execution of each command, ensuring the G-code CNC machine follows the programmed path accurately to complete the task. Each command (movement along an axis or a tool change) is processed sequentially to ensure the CNC machine follows the intended path and produces accurate results.

Is G-code used on All CNC Machines?

Yes, G-code is the industry-standard language used on the vast majority of CNC machines to convert design files into machine-readable instructions that control movements, tool changes, and operations with high precision. G-code provides instructions for movements, speeds, tool changes, and machine operations. It allows CNC machines to perform tasks with high accuracy, from basic movements to complex curves. Aerospace, automotive, and medical manufacturing industries require automation, precision, and efficiency throughout the production process.

For the mechanical engineer, G-code is more than a list of coordinates: it is the digital manifestation of tool-path kinematics and chip load management. Precision in CNC manufacturing requires a deep understanding of how these commands translate into mechanical acceleration, spindle torque, and the structural rigidity of the machine-tool-workpiece system.
Audrius Zidonis headshot
Audrius Zidonis PhD

What are the Examples of G Code Commands?

The examples of G-code commands are listed below.

  • Rapid Positioning (G00): Moves the tool to a specified position at maximum speed; while it stops precisely at the coordinates, it does not guarantee a straight-line path between points.
  • Linear Interpolation (G01): Moves the tool in a straight line to a specified position at a set feed rate.
  • Clockwise Circular Interpolation (G02): Moves the tool in a clockwise circular path to a specified position
  • Counterclockwise Circular Interpolation (G03): Moves the tool in a counterclockwise circular path to a specified position.
  • Dwell Time (G04): Pauses the machine for a specified amount of time before continuing the program.
  • Plane Selection (G17, G18, G19): Selects the plane for circular interpolation, G17 (XY plane), G18 (XZ plane), G19 (YZ plane).
  • Inches Mode (G20): Sets the machine to interpret measurements in inches.
  • Metric Mode (G21): Sets the machine to interpret measurements in millimeters.
  • Return to Machine Home (G28): Commands the machine to return to its home position.
  • Cancel Tool Radius Compensation (G40): Cancels any previously set tool radius compensation.
  • Tool Radius Compensation Left (G41): Moves the tool with compensation for the left side of the tool.
  • Tool Radius Compensation Right (G42): Moves the tool with compensation for the right side of the tool.
  • Machine Coordinate System (G53): Uses the machine's fixed coordinate system for movement.
  • Set Work Coordinate System (G92): Sets the workpiece's coordinate system, defining offsets from the machine's home position.

How does Feed Rate work in G code commands?

Feed rate in G-code commands specifies the speed at which the tool moves along a designated path during the machining process, with the rate being set in units of distance per minute for linear movements or distance per revolution for turning operations. The feed rate is set using the ‘F’ command followed by a numerical value F200), which sets the feed rate to 200 mm/min. The speed of the feed controls the cutting speed, influencing the precision and quality of the cut. A higher feed rate speeds up the process but compromises surface finish and precision. A slower feed rate improves accuracy and surface quality but increases machining time. Optimizing the feed rate depends on factors (material type, tool material, cutting depth, and the desired result). Balancing the feed rate is critical for achieving the best combination of efficiency and product quality.

Frequently Asked Questions on G-Code

Is G-Code a Programming Language?

Yes, G-code is a programming language used to control CNC machines, 3D printers, and other automated machinery. G-code consists of a series of structured, sequential instructions that a machine's controller follows to produce a specific physical part or movement. G-code directs machines to perform tasks (moving along specific paths, adjusting speeds, and changing tools). It is a bridge between human design and machine execution, making it an essential tool for controlling CNC machines and 3D printers. G-code is a programming language that converts design intent into machine actions.

What Is the Difference Between G-Code and M-Code?

The difference between G-code and M-code is that G-code controls the movement of the machine and defines paths, while the programmer ensures the code avoids obstacles. G-code is used across CNC machines, though certain machines or manufacturers implement slight variations in syntax or functionality. M-code handles specific actions (turning the coolant on or off, changing tools, or controlling features unique to certain machines). The M-Codes are often tailored by manufacturers for their specific equipment, making them highly machine-specific, while G-code follows a more general industry standard.

What is the G-code in VMC?

G-code in VMC (Vertical Machining Centers) consists of instructions used to control the machine's geometry and movements, while working alongside M-codes for tool actions, spindle states, and coolant settings. G-code guides the machine in performing operations (drilling, milling, and tapping) by specifying coordinates, speeds, and tool changes. The commands for a VMC include movement commands like G0 (rapid positioning), G1 (linear interpolation), and G2/G3 (circular interpolation), which dictate how the tool moves relative to the workpiece. It controls the machine's spindle speed, coolant settings, and the selection of tools. The VMC G-code list includes various codes for different machine functions (rapid positioning, linear interpolation, circular interpolation). The VMC G-code list provides the detailed commands required for precision operations. G-code VMC machine enables precise control, ensuring that the VMC follows the intended path and produces accurate results in the machining process. The versatility of G-code allows VMCs to be programmed for a wide range of operations, making them ideal for complex part production in industries (automotive, aerospace, and medical device manufacturing).

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.

Megan Conniff - Xometry Contributor
Megan Conniff
Megan is the Content Director at Xometry

Read more articles by Megan Conniff

Support
  • +1-800-983-1959

    support@xometry.com

Mailing Address

© 2026 Xometry, All Rights Reserved.

Privacy Policy | Terms of Use | Legal