What G-code describes
G-code is a line-oriented instruction language used by 3D printers, CNC machines and related motion systems. A line can request movement, change a modal setting, set a temperature or update a controller-specific feature.
A command is rarely meaningful in isolation. Its result can depend on unit mode, coordinate mode, extrusion mode, the machine configuration and the firmware interpreting the file. This reference therefore documents both the common meaning and the context that can change it.
G-code is better understood as a family of related dialects than as one perfectly uniform printer-file standard. Core motion syntax overlaps, while available commands, parameters, defaults and extensions depend on the target firmware and its configuration.
Read a command line
G1 X120 Y40 E1.6 F1800G1Requests a coordinated linear move.
X / YProvide the target position or distance, depending on G90/G91.
EProvides an extruder position or distance, depending on M82/M83.
FSets the feed rate. Printer files normally express it in millimeters per minute, and later moves often continue using the last value.
; ...Usually begins a comment for people or software. Slicers use comments to label layers and feature types, but those labels are not standardized.
A letter does not carry one context-free unit. X may be a coordinate, F a feed rate, while S can represent temperature, fan output or another setting. Interpret parameter words through the command that owns them.
A print file usually has three parts
Preparation
Sets units and positioning modes, starts heaters, homes axes, selects a tool, and may run leveling, cleaning or startup macros. This establishes how later values are interpreted.
Layered body
Large sequences of motion, extrusion, retraction, fan and temperature changes form the part. Layers and feature types are often marked by slicer comments rather than dedicated commands.
Shutdown
Turns off heaters and fans, lifts or parks the toolhead, releases motors, and may call a machine-specific end macro. A missing ending can leave the machine in a different post-job state.
; start: establish state
G21
G90
M83
G28
; body: travel, then print
G0 X40 Y20 Z0.20 F9000
G1 X80 Y20 E1.40 F1800
; end: stop active outputs
M104 S0
M140 S0
M107This is a structural illustration, not a complete file to run on any machine. Homing direction, heating order, park position and macro names must match the specific printer.
State changes the meaning
| State | Commands | Why it matters |
|---|---|---|
| Axis positioning | G90 / G91 | Following X, Y and Z values become absolute positions or relative distances. |
| Extrusion positioning | M82 / M83 | The E axis can use a mode independent from the motion axes. |
| Units | G20 / G21 | Coordinates and movement speeds may be interpreted in inches or millimeters. |
| Feed rate | F | Many interpreters retain the most recent F value until a later move changes it. |
| Active tool | T0 / T1... | On multi-tool machines, the same temperature or extrusion command may act on a different tool. |
| Coordinate reset | G92 | The current physical position can receive new logical coordinates without moving. |
Persistent state is a common source of misreading. E1.6 alone does not prove that 1.6 mm was added: under M83 it is the increment for this move, while under M82 it is the new cumulative position.
Firmware context matters
Marlin, Klipper, RepRapFirmware and CNC controllers overlap on core motion commands, but they do not form one perfectly interchangeable language. The same machine goal may use different command names, parameters or value scales.
| System | Extension model | What to check |
|---|---|---|
| Marlin | RepRap-style commands | Many features are compile-time options, so two builds of the same release may expose different commands. |
| Klipper | Standard subset + named extensions | It deliberately supports a common standard subset, adds names such as SET_PRESSURE_ADVANCE, and allows macros to add or override behavior. |
| RepRapFirmware | G-code everywhere + macros and expressions | Configuration, control and status reporting make extensive use of G-code, with newer releases also supporting meta-commands and expressions. |
| LinuxCNC / RS274NGC | CNC modal groups and coordinate systems | CNC concepts such as spindle control, tool compensation, work coordinates and canned cycles do not imply printer-style E-axis or heater behavior. |
Firmware name, version and configuration are therefore the minimum compatibility context. A file extension—or a successful run on someone else’s machine—does not prove identical execution on your printer.
How to inspect an unfamiliar file
- Identify the slicer, target machine and firmware. If that context is missing, treat compatibility as unknown.
- Read units, axis mode, extrusion mode, homing, tool and heater setup before interpreting later moves.
- Track X/Y/Z changes separately from E changes to distinguish travel, printing, retraction and priming.
- Treat semicolon comments as slicer-provided clues, not commands the machine necessarily executes, and do not assume all slicers use the same labels.
- For macros, named extensions or unfamiliar M-codes, check the official documentation for that firmware version instead of guessing from the number.
- Finally, check that the ending handles heaters, fans and other outputs, and that parking moves cannot exceed limits or hit the part.
What each command page contains
- A concise definition followed by the state required to interpret the command.
- Syntax and parameter meanings, with practical G-code examples.
- Firmware differences and mistakes that can change machine behavior.
- A transparent statement of what the local viewer can and cannot verify.
What the viewer can show
The viewer can show supported paths and selected file details. It cannot reproduce printer settings or predict exactly what a physical printer will do.
Start with these key commands
Official sources used for this guide
Reviewed on August 5, 2026 against the following primary sources. Together they explain the shared line structure and why controller dialects diverge.