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 type | Purpose |
|---|---|
| G-codes | Motion and geometry commands |
| M-codes | Machine operation commands |
| Coordinates | Position definitions |
| Feed commands | Movement speed control |
| Parameters | Machine-specific settings |
Each line usually defines a single machine operation.
Common G-code Commands
Several G-code commands are widely used across manufacturing systems.
| Command | Function |
|---|---|
G00 | Rapid movement |
G01 | Linear interpolation |
G02 | Clockwise arc movement |
G03 | Counterclockwise arc movement |
G21 | Metric units |
G90 | Absolute positioning |
G91 | Relative 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:
| Command | Function |
|---|---|
M03 | Start spindle clockwise |
M05 | Stop spindle |
M06 | Tool change |
M30 | End 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:
- Creating geometry in CAD
- Preparing operations in CAM
- Generating G-code
- Sending the program to the machine controller
- 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 mode | Description |
|---|---|
| Absolute positioning | Coordinates reference a fixed origin |
| Relative positioning | Coordinates 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
| Extension | Typical use |
|---|---|
.gcode | General machine instructions |
.nc | Numerical control programs |
.tap | CNC controller programs |
.cnc | Machine-specific control files |
Common Software Generating G-code
| Software | Typical use | Category |
|---|---|---|
| Fusion 360 | CNC machining | CAD/CAM |
| VCarve | CNC routing | CAM |
| Cura | 3D printing | Slicer |
| PrusaSlicer | Additive manufacturing | Slicer |
| LightBurn | Laser cutting | CAM |
See also
- CAM
- NC
- Toolpath
- CNC
- CNC Routing
- 3D Printing
- GRBL
- Marlin
- LinuxCNC
- Cartesian Coordinate System
