Skip to main content

G-code

G-code is a machine control language used to define movement, tool actions, and manufacturing operations in CNC and digital fabrication systems.

Last updated May 21, 2026

G-code is a machine control language used to define movement, tool behavior, and manufacturing operations in automated fabrication systems. G-code is widely used in CNC Routing, Milling, Laser Cutting, 3D Printing, industrial machining, and robotic manufacturing workflows.

G-code instructions are typically generated by CAM software or slicing software and executed by machine controllers such as GRBL, Marlin, or LinuxCNC.

The language forms the foundation of many modern machine control workflows.

What Is G-code?

G-code is a text-based programming language used to control automated machine movement.

The language defines operations such as:

  • axis movement
  • spindle control
  • extrusion control
  • tool changes
  • feed rate adjustment
  • coordinate positioning

G-code instructions are usually organized line-by-line as machine commands.

Example G-code:

G21 G90 G01 X100 Y50 F1200 M03 S18000

Meaning of G-code

The term G-code refers to “Geometric Code” or “Preparatory Code”.

The language originated from early Numerical Control (NC) systems and later evolved into modern CNC manufacturing workflows.

Many fabrication systems combine:

  • G-codes
  • M-codes
  • controller-specific commands

to fully control machine behavior.

Structure of G-code

A G-code program typically consists of sequential machine instructions.

Common command categories include:

Command typePurpose
G-codesMotion and geometry commands
M-codesMachine operation commands
CoordinatesPosition definitions
Feed commandsMovement speed control
ParametersMachine-specific settings

Each line usually defines a single machine operation.

Common G-code Commands

Several G-code commands are widely used across manufacturing systems.

CommandFunction
G00Rapid movement
G01Linear interpolation
G02Clockwise arc movement
G03Counterclockwise arc movement
G21Metric units
G90Absolute positioning
G91Relative positioning

Machine controllers may support additional proprietary commands.

M-codes

M-codes define machine operations that are not directly related to geometric movement.

Common M-codes include:

CommandFunction
M03Start spindle clockwise
M05Stop spindle
M06Tool change
M30End program

M-codes are often combined with G-code instructions within the same machining program.

G-code in CNC Machining

G-code is heavily used in subtractive manufacturing workflows.

Common applications include:

  • CNC Routing
  • Milling
  • Turning
  • Drilling
  • engraving
  • cutting operations

A typical CNC workflow includes:

  1. Creating geometry in CAD
  2. Preparing operations in CAM
  3. Generating G-code
  4. Sending the program to the machine controller
  5. Executing the machining process

G-code in 3D Printing

Most desktop 3D printers also use G-code-based control systems.

In additive manufacturing workflows, G-code commonly defines:

  • nozzle movement
  • extrusion amount
  • layer transitions
  • print temperature
  • cooling fan behavior
  • retraction operations

Slicing software converts polygon geometry such as STL or 3MF into printable G-code instructions.

Coordinate Systems

G-code relies on coordinate systems to define machine movement.

Important concepts include:

  • Cartesian Coordinate System
  • work offsets
  • machine coordinates
  • homing
  • tool offsets
  • zero positions

Incorrect coordinate setup may result in positioning errors or machine collisions.

Feed Rate and Speed Control

G-code defines manufacturing parameters that strongly affect machining behavior.

Important parameters include:

  • feed rate
  • spindle RPM
  • acceleration
  • extrusion rate
  • laser power
  • plunge speed

Proper parameter selection influences:

  • surface finish
  • machining efficiency
  • tool wear
  • dimensional accuracy
  • material behavior

Absolute vs Relative Positioning

G-code commonly supports two positioning methods.

Positioning modeDescription
Absolute positioningCoordinates reference a fixed origin
Relative positioningCoordinates reference current position

Absolute positioning commonly uses the G90 command, while relative positioning uses G91.

Controllers and Compatibility

Different machine controllers may interpret G-code differently.

Common controllers include:

  • GRBL
  • Marlin
  • LinuxCNC
  • Mach3
  • Smoothieware

Because of controller differences, some G-code programs require machine-specific modifications.

Advantages of G-code

G-code offers several advantages in digital fabrication workflows.

  • precise machine automation
  • broad industry adoption
  • compatibility with CAM systems
  • repeatable manufacturing
  • efficient motion control
  • support for complex machining operations

These characteristics make G-code one of the most important machine-control standards.

Limitations of G-code

G-code also has several limitations.

  • controller incompatibility
  • limited human readability in complex programs
  • machine-specific syntax variations
  • limited high-level process abstraction
  • risk of machine collision errors

Improper G-code may damage tools, materials, or machines.

Common File Extensions

ExtensionTypical use
.gcodeGeneral machine instructions
.ncNumerical control programs
.tapCNC controller programs
.cncMachine-specific control files

Common Software Generating G-code

SoftwareTypical useCategory
Fusion 360CNC machiningCAD/CAM
VCarveCNC routingCAM
Cura3D printingSlicer
PrusaSlicerAdditive manufacturingSlicer
LightBurnLaser cuttingCAM

See also