G-code is the language CNC machines speak. It is a plain-text list of instructions, one per line, that tells the machine where to move, how fast, and when to switch things (like the hot wire) on and off. Every CNC tool — mills, lathes, 3D printers, foam cutters — runs some dialect of it.
Anatomy of a line
A line is a letter-number command (a "word"), optionally followed by coordinates:
G1 X10.5 Y20 U10.5 V20 F400
- G1 — the command: a straight cutting move.
- X / Y — target position of the left wire end.
- U / V — target position of the right wire end (on 4-axis machines).
- F400 — feedrate (speed) for this move, in units per minute.
The machine reads each line in order and moves accordingly.
The commands you will see
| Code | Meaning |
|---|---|
G0 | Rapid move (positioning, wire off) — go fast, no cutting. |
G1 | Linear cutting move at the feedrate. |
G4 P<s> | Dwell — pause for P seconds (used for wire pre-heat). |
G90 / G91 | Absolute / relative coordinates. |
G21 | Units are millimetres. |
G92 | Set the current position as a given value (e.g. zero). |
M8 / M9 | Turn an output on / off — used here for the hot wire. |
M30 | End of program. |
Coordinates & origin
Positions are measured from a work zero (origin). In absolute mode (G90) every coordinate is relative to that zero. Setting the origin correctly — physically, on the machine — is what makes the cut land where you intend.
You rarely write it by hand
For foam cutting you do not type G-code; a tool like cncfoam.com generates it from your shape and settings. But being able to read it is invaluable for sanity-checking a job — which is why the tool includes a colour-coded G-code viewer. Next: G-code for foam cutting.