
G-code is a programming language used to control numerically controlled machine tools. A program is written as a sequence of short blocks, each containing commands that tell the controller how to move the tool, how fast to move it, and which machine functions to switch on or off. The format is standardized internationally, which is why a program written for one machine can often be read on another machine of the same class [1].
The name comes from the letter G used for motion commands, such as rapid positioning and linear or circular interpolation. Other letters address different functions: S sets spindle speed, F sets feed rate, T selects a tool, and M covers miscellaneous machine actions such as coolant control or program end. Coordinates are usually given in X, Y and Z, with additional rotary axes labelled A, B and C.
A controller reads the blocks in order and executes them. Motions may be absolute, measured from a fixed origin, or incremental, measured from the current position. Modern controls also support fixed cycles, which compress repeated operations such as drilling into a single command. Because the format defines only the instructions and not the machining strategy, the same part can be programmed in very different ways.
In practice, most complex parts are generated by CAD/CAM software rather than typed by hand. The software calculates toolpaths and exports a G-code program, which is then loaded into the machine. Operators still need to understand the language to verify a program, make small edits at the machine, and diagnose why a toolpath behaves unexpectedly.
G-code is an established but relatively low-level format. Newer data models such as STEP-NC aim to describe machining tasks in terms of features and processes rather than individual tool movements, but G-code remains the common interchange format on shop floors [1].
Quick reference: G-code and M-code table — the same codes listed with their modal groups, for use at the machine.