ThingConnect

CNC programs & data

G-code

G-code is the programming language most CNC machines run — line-by-line commands that tell the machine where to move, how fast, and along which path.

Updated November 20263 min read

← All glossary terms

Whether a program comes from CAM software or is typed at the machine, the control executes it as G-code. The name comes from the “G” words that set motion, but a program is a mix of G-codes, M-codes and values for feed, speed and tool.

Reading a line of G-code

N40 G01 X50.0 Z-20.0 F0.2 reads as: block 40, feed in a straight line to X50 Z−20 at 0.2 mm per revolution. N numbers the block, G sets the motion, X/Y/Z give the target, and F, S and T set feed, spindle speed and tool.

Common G-codes

  • G00

    Function
    Rapid positioning — move fast, not cutting
  • G01

    Function
    Linear interpolation — straight-line feed (cutting)
  • G02 / G03

    Function
    Circular interpolation — clockwise / counter-clockwise arc
  • G17 / G18 / G19

    Function
    Select the XY / XZ / YZ plane for arcs
  • G20 / G21

    Function
    Inch / millimetre units
  • G28

    Function
    Return to machine reference position
  • G40 / G41 / G42

    Function
    Cutter compensation off / left / right
  • G54

    Function
    First work offset (G55–G59 for others)
  • G90 / G91

    Function
    Absolute / incremental positioning

Lathes and mills share most of these but differ on some, and each control maker adds its own codes.

Frequently asked questions

G-codes control geometry and motion — where the tool moves, how fast and along which path. M-codes control machine functions such as the spindle, coolant, tool changes and program stops. A typical program line mixes both, along with feed (F), speed (S) and tool (T) words.

CAM writes the program, but programmers and operators still read G-code to prove out a job, edit a feed or an offset, restart partway through a program, or find out why a move went wrong. Reading the common codes covers most of that; writing whole programs by hand is now rarer.

Related terms

Filed under

CNC programs & data

Live demo

See ThingConnect on a real shop floor

A one-on-one walkthrough with our team.

Book a demo
Talk to our team

See which program and which part every machine is running, as it runs