List of G and M Codes for CNC Programming
Search and filter ISO commands by control, machine or function.
The CNC programming language is based on structured code blocks that control toolpaths, feeds and machine-tool functions. In this list of G and M codes you'll find a quick reference to the commands most used in turning and milling. Although an ISO standard exists, the exact execution of a canned cycle or an advanced interpolation can vary depending on the Fanuc, Heidenhain, Siemens or Haas control and the manufacturer's parameters.
Add my codesClose my codes
FiltersClose filters
Heidenhain LBL
Labels and subroutines
Defines and calls labels/subroutines to repeat blocks or patterns.
Syntax / example
LBL 1 / CALL LBL 1
Machine: Milling, Mill-turn
Risk: Medium
Controls: Heidenhain
Heidenhain
- Review returns and repetitions to avoid unwanted loops.
G00
MovementQuick positioning
Fast movement to a coordinate without controlling cutting advance.
G01
MovementLinear interpolation
Controlled linear movement with programmed advance.
G02
MovementHourly circular interpolation
Circular arc clockwise in the active plane.
G02.1/G03.1
InterpolationSpiral interpolation (circular threading B)
CW/CCW spiral interpolation: continuous helical motion with variable pitch; used in B threading and some lapping operations.
G02.2/G03.2
InterpolationInvolute interpolation
Interpolation along an involute circle (involute interpolation), used in gear manufacturing.
G03
MovementCounterclockwise circular interpolation
Counterclockwise circular arc in the active plane.
G04
Program controlTimed dwell
Temporarily stops execution for a defined time or number of revolutions.
G05/G05.1
High speedHigh speed / AI contour
Enables high-speed machining functions, path look-ahead or advanced contour control.
G5/G5.1/G5.2
Advanced interpolationSplines and NURBS
Interpolations by cubic spline, quadratic spline or NURBS in controls that support it.
G05.4
High speedHRV3/HRV4 on/off
Enables or disables HRV3/HRV4 (High Response Vector) current control to improve servo precision at high speed.
G06.2
High speedNURBS interpolation
Interpolation of NURBS (Non-Uniform Rational B-Spline) curves directly in the control, reducing block points and improving smoothness.
G07
InterpolationHypothetical axis interpolation
Defines a hypothetical (virtual) axis for interpolation; used when machining symmetrical parts or to coordinate non-physical moves.
G7/G8
LatheDiameter/radius mode around lathe
Selects whether lathe X coordinates are read as diameter or radius depending on the control.
G08/G09
ToolpathSmoothing and block-wise exact stop
Functions used to activate/deactivate smoothing or require exact stopping in a specific block according to control.
G10
OffsetsOffset writing
Lets you write tool offsets, work offsets or other data from the program.
G12/G13
Milling cyclesCircular pocket
Circular interpolation cycle to machine pockets or circular patterns according to control.
G15/G16
CoordinatesPolar coordinates
Activates or cancels programming in polar coordinates, usually radius and angle.
G17/G18/G19
DrawingPlane selection
Defines the active plane for arcs and offsets.
G20/G21
UnitsUnits inches/millimeters
Select programming in inches or millimeters.
G22/G23
SafetyProgrammed stroke limits
Activates or deactivates zone checking/stored limits according to control.
What are preparatory (G) and auxiliary (M) codes?
G codes prepare and govern tool movement: rapid traverses, linear interpolation, circular interpolation, canned cycles, working planes and compensations. M codes control auxiliary machine functions such as spindle, coolant, stop, tool change or program end.
Main programming categories
Movement and interpolation (G00, G01, G02, G03)
G00 is used for rapid positioning, G01 for linear cutting feed and G02/G03 for clockwise or counterclockwise circular interpolation. They are the basis of most CNC programs on milling machines and lathes.
Canned cycles and subprograms
Canned cycles simplify repetitive operations such as drilling, tapping, boring or roughing. Their syntax varies a lot between controls, so it's always wise to check the machine manual.
Frequently Asked Questions (FAQ)
What is the difference between a G code and an M code?
G codes (preparatory) define the geometry and tool movement, such as linear interpolations or roughing cycles. M codes (miscellaneous or auxiliary) control the machine hardware, such as starting the spindle (M03), the coolant (M08) or the end of program (M30).
Are G-codes universal for all lathes and milling machines?
Not entirely. Although basic moves such as G00, G01, G02 and G03 are universal, complex canned cycles like G71 for roughing or G83 for peck drilling have different syntax and parameters depending on whether you use Fanuc, Haas, Siemens or Heidenhain.
What is the G01 code and when is it used?
G01 is the linear interpolation code. It tells the tool to move in a straight line to a given coordinate at a controlled cutting feed programmed with the letter F.
What is the difference between codes G90 and G91?
G90 sets absolute positioning, where every coordinate is measured from the part zero (origin). G91 activates incremental positioning, where each new move is calculated from the tool's current position.
What are G41 and G42 codes used for in machining?
These codes activate tool or insert radius compensation. G41 offsets the path to the left of the programmed contour relative to the feed direction, G42 to the right. They are used to machine profiles, chamfers and radii to exact size without gouging.
How are fixed cycles and compensations cancelled?
To avoid crashes you must cancel modal functions once they are no longer needed. G80 cancels any active canned cycle, such as drilling cycles. G40 cancels tool radius compensation, and G49 cancels length compensation, widely used on milling machines.
What are the essential auxiliary M codes?
The most standardised hardware codes are M03 (spindle clockwise), M04 (spindle counter-clockwise), M05 (spindle stop), M08 (coolant on), M09 (coolant off) and M30 (end of program, axes stop and rewind).
Do Fanuc canned cycles work the same on other controls?
No. Although interpolation moves (G00 to G03) are a widely adopted ISO standard, the syntax of complex cycles differs. For example, the lathe roughing cycle is G71 on Fanuc, but Siemens requires a different parameter structure such as CYCLE95.
What does the letter F, S and T mean in the CNC code?
Alongside the G and M codes, the letter F (feed) sets the cutting feed, the letter S (speed) sets the spindle rpm or cutting speed, and the letter T (tool) calls the tool number and its offset in the turret or magazine.
Related tools
CNC simulator & editor
CNC IDE: editing with G/M tooltips, line inspector, conversion between controls and 2D/3D toolpath.
CNC Alarms Guide
CNC Alarms and Solutions Guide. Enter the error code or symptom to find the cause and how to repair it at the machine.
Calculate cycle time
Estimate the cycle time of a CNC program: cutting, rapids, canned cycles, dwells and tool changes. Parts/hour and breakdown by item.