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.

These codes can vary depending on the control, post-processor, machine and manufacturer parameters. Before running a real program, confirm the syntax in the official machine/control manuals and simulate the toolpath. GetGCode is not liable for personal injury, material damage, production stoppages, programming errors, diagnostic errors or decisions made from this indicative information. The trademarks cited belong to their respective owners (see Legal notice).
Add my codes
You can use the table freely. Saving your own codes is reserved for accounts with Pro access.
Code
Name
Family
Example
What does it do
Filters

Siemens CYCLE70

Siemens thread milling

Siemens cycle for milling internal or external threads with a thread mill.

Return to dictionary

Syntax / example

CYCLE70(..., RFP, RTP, SDIS, DP, DM, APP, ROP, TDEP, FAL, IFORM, ...)

Machine: Milling, Mill-turn

Risk: High

Controls: Siemens

Siemens

  • Check pitch, direction, tool diameter and number of passes.

G00

Movement

Quick positioning

Fast movement to a coordinate without controlling cutting advance.

G01

Movement

Linear interpolation

Controlled linear movement with programmed advance.

G02

Movement

Hourly circular interpolation

Circular arc clockwise in the active plane.

G02.1/G03.1

Interpolation

Spiral 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

Interpolation

Involute interpolation

Interpolation along an involute circle (involute interpolation), used in gear manufacturing.

G03

Movement

Counterclockwise circular interpolation

Counterclockwise circular arc in the active plane.

G04

Program control

Timed dwell

Temporarily stops execution for a defined time or number of revolutions.

G05/G05.1

High speed

High speed / AI contour

Enables high-speed machining functions, path look-ahead or advanced contour control.

G5/G5.1/G5.2

Advanced interpolation

Splines and NURBS

Interpolations by cubic spline, quadratic spline or NURBS in controls that support it.

G05.4

High speed

HRV3/HRV4 on/off

Enables or disables HRV3/HRV4 (High Response Vector) current control to improve servo precision at high speed.

G06.2

High speed

NURBS interpolation

Interpolation of NURBS (Non-Uniform Rational B-Spline) curves directly in the control, reducing block points and improving smoothness.

G07

Interpolation

Hypothetical axis interpolation

Defines a hypothetical (virtual) axis for interpolation; used when machining symmetrical parts or to coordinate non-physical moves.

G7/G8

Lathe

Diameter/radius mode around lathe

Selects whether lathe X coordinates are read as diameter or radius depending on the control.

G08/G09

Toolpath

Smoothing and block-wise exact stop

Functions used to activate/deactivate smoothing or require exact stopping in a specific block according to control.

G10

Offsets

Offset writing

Lets you write tool offsets, work offsets or other data from the program.

G12/G13

Milling cycles

Circular pocket

Circular interpolation cycle to machine pockets or circular patterns according to control.

G15/G16

Coordinates

Polar coordinates

Activates or cancels programming in polar coordinates, usually radius and angle.

G17/G18/G19

Drawing

Plane selection

Defines the active plane for arcs and offsets.

G20/G21

Units

Units inches/millimeters

Select programming in inches or millimeters.

G22/G23

Safety

Programmed 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