Guide · 2 min read

What G-code looks like, and why it matters

The plain text file every CNC router runs: what it is, the codes you'll see most, and why one machine's file may not suit another.

Hobby CNC routers, including the GRBL-based machines on this site, run on G-code. You rarely write it by hand, but it helps to know what it is, because it's the file you send to the machine.

DesignCAD: draw the partToolpathsCAM: choose bits, cutsG-codea text file of movesSenderstreams the fileControllerturns moves into stepsMachinemotors and spindle
Where G-code sits: CAM software writes it, and the controller reads it.

What G-code is

Wikipedia describes it as "G-code (abbreviation for geometric code; also called RS-274, standardized today in ISO 6983-1)". It's a plain text file. Each line holds instructions for the machine: move somewhere, switch the spindle on, change units. Design software doesn't send drawings to the machine; CAM software turns the drawing into these lines, which Wikipedia describes as "applications that could output the appropriate G-code to operate a specific machine".

The words you'll see most

A line is made of "words": a letter and a number. These are some of the most common, with descriptions quoted from the LinuxCNC manual, an open-source CNC controller whose documentation explains each code:

CodeWhat it doesFrom the manual
G0Rapid moveLinuxCNC's manual: G0 produces "coordinated motion to the destination point at the maximum rapid rate (or slower)" and "is typically used as a positioning move."
G1Straight-line move at the feed rate"For linear (straight line) motion at programmed feed rate (for cutting or not), program G1".
G2 / G3Arcs"A circular or helical arc is specified using either G2 (clockwise arc) or G3 (counterclockwise arc)".
G20 / G21Units"G20 - to use inches for length units" and "G21 - to use millimeters for length units".
G90 / G91Absolute or relative positionsIn absolute mode, positions are "in terms of the currently active coordinate system"; in incremental mode they "represent increments from the current coordinate".
X Y ZWhere to move toThe axis letters. LinuxCNC's example: "G0 X2.5 (rapid move to coordinate X2.5 including any offsets in effect)".
FFeed rate"Fx - set the feed rate to x. x is usually in machine units (inches or millimeters) per minute."
S with M3 / M5Spindle on and off"M3 - start the selected spindle clockwise at the S speed" and "M5 - stop the selected spindle."

The numbers in a real file (positions, feed rates, spindle speeds) come from your CAM settings, and this guide doesn't suggest any.

Why one machine's file may not suit another

G-code isn't one fixed language. Wikipedia notes that "Extensions and variations have been added independently by control manufacturers and machine tool manufacturers" and that "G-code has many variants." That's why CAM software writes G-code for a specific machine, as in Wikipedia's description above, rather than one file for every controller. On this site, 23 of the 43 machines name GRBL or grblHAL in their controller description; the GRBL guide covers what that firmware is.

Sources

Wikipedia read on 4 November 2026; LinuxCNC manual read from its GitHub repository on 4 November 2026 (commit cdf957b, 3 November 2026). Quotes are copied from these pages.