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.

For reference only: syntax changes with the control, the post-processor and the machine parameters. Check the official manual and run a simulation before cutting. 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

Fast movement to a coordinate without controlling cutting advance.

Controlled linear movement with programmed advance.

Circular arc clockwise in the active plane.

CW/CCW spiral interpolation: continuous helical motion with variable pitch; used in B threading and some lapping operations.

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

Counterclockwise circular arc in the active plane.

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

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

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

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

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

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

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

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

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

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

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

Defines the active plane for arcs and offsets.

Select programming in inches or millimeters.

Activates or deactivates zone checking/stored limits according to control.

Every G and M code, one by one

The full catalogue grouped by family. Each code opens its own page with the syntax for each control, an example and the typical mistakes.

Haas manufacturer

Heidenhain

Siemens

Program control

Advanced interpolation

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