Common G-code commands for CNC milling and turning
G-codes control motion, coordinate systems, tool compensation, and canned cycles on CNC machines. This reference covers the most-used G-codes across Fanuc, Haas, Mazak, and Siemens controls. Most are standardised by ISO 6983 and RS-274; differences are noted.
- G00 Rapid Positioning: Moves at maximum speed to specified coordinates. Not for cutting. G00 X50 Y25 Z5
- G01 Linear Interpolation: Cutting feed in a straight line. G01 X100 F500
- G02/G03 Circular Interpolation: Clockwise (G02) / Counter-clockwise (G03) arc. G02 X50 Y0 I25 J0 F400
- G17/G18/G19 Plane Selection: XY (G17, default milling), ZX (G18), YZ (G19). Must match arc plane.
- G20/G21 Units: Inch (G20) / Metric (G21). Always specify at the program start.
- G40/G41/G42 Cutter Compensation: Cancel (G40), Left (G41), Right (G42). Compensates tool radius for contour milling.
- G43/G49 Tool Length Compensation: G43 H(tool number) applies length offset; G49 cancels.
- G54-G59 Work Coordinate Systems: Up to 6 standard work offsets. Additional extended offsets (G54.1 P1-P48) on modern controls.
- G81-G89 Canned Cycles: Drilling (G81), peck drilling (G83), tapping (G84), boring (G85/G86). Cancel with G80.
- G90/G91 Absolute/Incremental: G90 = positions from work zero; G91 = positions from current location.
How to use this G-Code Reference Guide
Use this reference to look up G-code meanings, syntax, and control-specific notes. G00-G03 cover 90% of motion commands. Canned cycles (G81-G89) handle drilling and tapping. G40-G42 and G43 are essential for precise tool compensation. Always verify G-code support on your specific machine control -- some older controls lack newer G-codes.
Common mistakes to avoid
- Not cancelling canned cycles with G80 before moving to a new position -- the machine will try to drill at every XY position.
- Mixing absolute (G90) and incremental (G91) accidentally -- a common crash cause when the mode is not explicitly set.
- Forgetting to apply tool length compensation (G43) after a tool change -- the tool will go to the wrong Z position, potentially crashing.