G Code
G-code, or geometric code, is the plain-text programming language used to command CNC machines, specifying where to move, how to move, and at what speed. It is the executable toolpath layer between CAM output and machine motion, controlling linear and circular moves, feed rate, spindle speed, and tool selection. Commonly associated with RS-274 and ISO 6983 standards, it enables precise reproduction of cuts on mills, lathes, routers, and lasers.
On the shop floor, G-code is the critical link between CAM and machine motion. Typically generated via CAM software then post-processed into the specific machine dialect, the code is verified in simulation before being loaded into the controller. Operators run production parts repeatedly, maintaining tolerance through accurate coordinate offsets and tool length compensation. Because G-code directly governs toolpath geometry and feed motion, any errors in coordinates, units, offsets, or modal commands can produce undersize features, bad finishes, or scrap even if the CAD model is perfect. In millwork and router environments, G-code drives nested cutting, profiling, drilling, and pocketing with the same core logic as metal machining, though machine dialects vary by brand. The program lines like G01 X... Y... Z... F... tell the machine to interpolate a feed move at a programmed feed rate, while modal commands like absolute/incremental positioning remain in effect until changed, so an incorrect modal state can alter every subsequent move. This explains why rigorous verification and post-processing are essential for reliable production.
- Wrong units or coordinate mode: If the program is written for millimeters but the control is set to inches, or absolute vs. incremental positioning is mishandled, the machine can crash or destroy the part.
- Modal-state carryover: G-code modes like active plane or feed rate persist until changed; an operator assuming a later line resets the machine may cause arcs to bow, holes to mislocate, or toolpaths to cut incorrectly.
- Dialect mismatch between CAM post and machine: Different machine builders implement G-code variants, so a program posted for one controller may use commands or syntax that another control interprets differently, causing alarms, wrong motion, or unsupported functions.
What is the difference between G-code and M-code?
G-code controls geometric motion and machining path behavior, while M-code handles miscellaneous machine functions such as spindle start/stop, coolant, and auxiliary actions.
Is G-code the same on every machine?
No, there is a common core, but controllers and manufacturers use different dialects, so post-processing and verification are machine-specific.
What does a basic G-code block contain?
A block often includes a line number and command words such as G, X, Y, Z, F, S, T, and M, which specify motion, coordinates, feed, spindle speed, tool selection, and auxiliary functions.