Skip to content

G-code and ISO 6983: the language behind the CNC machine

From G00 and G01 to tool correction and zero points — how you talk to the controller

Although modern workshops programme much in CAD/CAM G-code is still the language the machine actually understands. A skilled CNC technician can read a programme line see what the machine will do and correct an error without going back to the computer. G-code is based on the international standard ISO 6983 (also known as RS-274). The standard sets out the basic structure but each controller — Fanuc Siemens Heidenhain Haas — has its own dialect with small differences. That is why the rule applies: know your machine's manual.

§G-codes control movement

G-codes (from 'geometric' or 'preparatory') determine how the tool moves. The most important movement codes are few and used constantly. G00 is rapid movement: the machine runs as fast as it can to a position — used to move away from the part, never for cutting. G01 is linear feed in a straight line at the set feed rate F, and it's the most common cutting movement. G02 and G03 cut circular arcs — G02 clockwise, G03 counterclockwise.

G-codeFunction
G00Approach (positioning without cutting)
G01Linear movement with tension F
G02 / G03Circular arc with / against the clock
G40 / G41 / G42Tool radius correction: cancel / left / right
G54–G59Part zero points (work coordinate systems)
G96 / G97Constant cutting speed / constant rpm

§M-koder styrer maskinen

Where G-codes control geometry, M-codes (miscellaneous, 'miscellaneous') control the machine itself. M03 starts the spindle clockwise, M04 counter-clockwise, and M05 stops it. M06 changes the tool. M08 turns on the coolant, M09 turns it off. M00 is a program stop, and M30 ends the program and rewinds to the start. A typical program alternates between G and M codes line by line: change tool, start spindle, turn on cooling, move in, cut, move out, turn off.

§The zero point: where in the world is the item?

The machine has its own fixed machine zero point but the program is calculated from a workpiece zero point which you yourself place at a logical location on the workpiece — typically in a corner or at the centre. The workpiece zero point is activated with G54 to G59. During setup you find the zero point with an edge probe or a dial gauge and write the offset into the machine. If you miss the zero point the entire workpiece sits offset regardless of how perfect the program otherwise is. Therefore zero point setting is one of the setup actions requiring the most care.

§Tool correction: so the contour fits

The program describes the desired contour, but the cutter has a radius that must be accounted for. With tool radius compensation (G41 left, G42 right, G40 to cancel), the control automatically offsets the path by the tool's radius, so it's the contour — not the tool's center — that comes out right. Similarly, length compensation accounts for each tool having its own length. The advantage is that you can switch to a slightly different tool and just change the correction value in the table instead of rewriting the program.

  • 01One block (line) typically consists of an N-number, a G-code, coordinates (X, Y, Z) and possibly F and S
  • 02Absolute (G90) and incremental (G91) coordinates specify whether measurements are from the origin or from the last position
  • 03Comments in parentheses make the program readable for the next technician
  • 04Simulation before driving catches collisions before they happen in reality

If you can read G-code, you own the machine. If you can only press buttons, the machine owns you.