G-CODE · M-CODEG-code and M-code list

G and M codes for machining centers and lathes, centered on the common FANUC-type assignments. The same number can mean different things on different machines (M codes in particular are assigned by the machine builder). Always confirm against your machine’s manual before running a program.

Most-used M codes (common FANUC-type assignments; they differ by machine builder and model, so your machine’s manual comes first): M03 spindle forward, M05 spindle stop, M06 tool change, M08 coolant on, M09 coolant off, M30 program end and rewind, M98 subprogram call.

M code list · Quick comparison between controls · Codes whose numbers clash · Exact stop (G09, G61) · Decimal point input: is X1000 1000 mm or 1 mm? · CNC programming practice problems (30, graded)

Same number,
different machine?
Check the manual!

Chips, the Kezuriba mascot

G codes

CodeMachining centerLathe (system A)Modal
G00Rapid positioning (rapid traverse)Rapid positioning (rapid traverse)Modal (01)
G01Linear interpolation (cutting feed)Linear interpolation (cutting feed)Modal (01)
G02Circular interpolation, clockwise (CW) / helical interpolationCircular interpolation, clockwise (CW) / helical interpolationModal (01)
G03Circular interpolation, counterclockwise (CCW) / helical interpolationCircular interpolation, counterclockwise (CCW) / helical interpolationModal (01)
G04Dwell (pause)Dwell (pause)One-shot (00)
G07.1Cylindrical interpolationCylindrical interpolationModal
G09Exact stop (this block only)Exact stop (this block only)One-shot (00)
G10Programmable data input (writes offset values and work coordinates from the program)Programmable data input (writes offset values and work coordinates from the program)One-shot (00)
G12.1–G13.1Polar coordinate interpolation (ON with G12.1, OFF with G13.1)Polar coordinate interpolation (ON with G12.1, OFF with G13.1)Modal
G17XY plane selectionXY plane selection (used on lathes with milling capability)Modal (02)
G18ZX plane selectionZX plane selection (lathe standard)Modal (02)
G19YZ plane selectionYZ plane selection (lathes with a Y axis and live tooling)Modal (02)
G20Inch inputInch inputModal (06)
G21Metric (mm) inputMetric (mm) inputModal (06)
G28Automatic return to reference point (zero return)Automatic return to reference point (zero return)One-shot (00)
G302nd (3rd, 4th) reference point return2nd (3rd, 4th) reference point returnOne-shot (00)
G31Skip function (moves in a straight line until a signal comes in)Skip function (moves in a straight line until a signal comes in)One-shot (00)
G32—Threading (feed for one pass)Modal (01)
G40Cutter radius compensation cancelTool nose radius compensation cancelModal (07)
G41Cutter compensation left (tool is on the left of the direction of travel)Tool nose radius compensation, leftModal (07)
G42Cutter compensation right (tool is on the right of the direction of travel)Tool nose radius compensation, right (used for typical OD turning toward –Z)Modal (07)
G43Tool length compensation + (adds the offset)(Not used on typical FANUC-type lathes. The tool offset is selected by the last 2 digits of the T code)Modal (08)
G43.4Tool center point control (5-axis)—Modal
G44Tool length compensation – (subtracts the offset)—Modal (08)
G49Tool length compensation cancel—Modal (08)
G50Scaling cancelMaximum spindle speed setting (also sets the coordinate system in system A)Modal (11)
G52Local coordinate system settingLocal coordinate system settingOne-shot (00)
G53Machine coordinate system selection (positioning in machine coordinates)Machine coordinate system selection (positioning in machine coordinates)One-shot (00)
G54–G59Work coordinate systems 1–6 selectionWork coordinate systems 1–6 selectionModal (14)
G61Exact stop modeExact stop modeModal (15)
G64Cutting mode (continuous cutting; cancels exact stop)Cutting mode (continuous cutting; cancels exact stop)Modal (15)
G65Macro call (simple call, with arguments)Macro call (simple call, with arguments)One-shot (00)
G66Modal macro callModal macro callModal (12)
G67Modal macro call cancelModal macro call cancelModal (12)
G68Coordinate rotationDiffers by machine (mirror of the opposed tool post, or coordinate rotation)Modal (16)
G68.2Tilted working plane command (tilted coordinate system for 3+2 machining)—Modal
G69Coordinate rotation cancelDiffers by machine (mirror OFF of the opposed tool post, or coordinate rotation cancel)Modal (16)
G70—Finishing cycle (finishes the profile rough-cut with G71–G73)One-shot (00)
G71—OD/ID rough turning cycle (cuts along Z)One-shot (00)
G72—Face rough turning cycle (cuts along X)One-shot (00)
G73High-speed peck drilling cycle (chip breaking, small retract)Pattern repeating (closed-loop cutting) cycle (cuts following the stock shape, e.g. castings)Modal (09)
G74Left-hand tapping cycle (reverse tapping)End face grooving cycle / Z-direction deep hole peck drillingModal (09)
G75—OD/ID grooving (cut-off) cycleOne-shot (00)
G76Fine boring cycleMultiple thread cutting cycle (compound thread cutting cycle)Modal (09)
G80Canned cycle cancelDrilling canned cycle cancel (for live tooling, face drilling)Modal (09)
G81Drilling cycle (spot drilling)—Modal (09)
G82Drilling cycle (counter boring, dwell at hole bottom)—Modal (09)
G83Deep hole drilling cycle (peck drilling, full retract to the R point each time)End face deep hole drilling cycle (live tooling, lathe with C axis)Modal (09)
G84Tapping cycle (right-hand thread)Face tapping cycle (lathe with live tooling)Modal (09)
G85Boring cycle (feed in, feed out)Face boring (drilling) cycle (live tooling)Modal (09)
G86Boring cycle (spindle stops at the hole bottom, rapid out)—Modal (09)
G87Back boring cycle (reverse spot facing)Side deep hole drilling cycle (live tooling, systems A/B)Modal (09)
G88Boring cycle (dwell at the hole bottom, spindle stop, manual retract)Side tapping cycle (live tooling, systems A/B)Modal (09)
G89Boring cycle (dwell at the hole bottom, feed out)Side boring (drilling) cycle (live tooling)Modal (09)
G90Absolute commandOD/ID cutting cycle (single canned cycle, G-code system A)Modal (03)
G91Incremental command(Not used in system A. Incremental values are written with U/W)Modal (03)
G92Coordinate system setting (assigns coordinate values to the current position)Thread cutting cycle (single canned cycle, G-code system A)One-shot (00)
G94Feed per minute (mm/min)Face cutting cycle (single canned cycle, G-code system A)Modal (05)
G95Feed per revolution (mm/rev)—Modal (05)
G96Constant surface speed controlConstant surface speed controlModal (13)
G97Constant surface speed control cancel (constant spindle speed)Constant surface speed control cancelModal (13)
G98Canned cycle: return to initial pointFeed per minute (mm/min) (G-code system A)Modal (10)
G99Canned cycle: return to R pointFeed per revolution (mm/rev) (G-code system A)Modal (10)

Yellow underline = the meaning differs between machining centers and lathes.

M codes

CodeMeaningMachine
M00Program stopMachining center, Lathe
M01Optional stop (conditional stop)Machining center, Lathe
M02Program endMachining center, Lathe
M03Spindle on, clockwise (CW)Machining center, Lathe
M04Spindle on, counterclockwise (CCW)Machining center, Lathe
M05Spindle stopMachining center, Lathe
M06Tool change (ATC)Machining center
M07Mist coolant ON (number and meaning differ by machine)Machining center, Lathe
M08Coolant (cutting fluid) ONMachining center, Lathe
M09Coolant OFFMachining center, Lathe
M19Spindle orientation (oriented spindle stop)Machining center, Lathe
M29Rigid tapping (switches the spindle to position control) *machine-dependent*Machining center, Lathe
M30Program end and rewind (end of tape)Machining center, Lathe
M41–M44Switching the spindle gear (speed range)Machining center, Lathe
M98Subprogram callMachining center, Lathe
M99Subprogram end (return to the caller)Machining center, Lathe

Quick comparison between controls

How the same function is commanded on different controls. The “Machine” column shows whether the function is used on lathes, machining centers or both. Click a function to open its page.

FunctionMachineFANUC-compatible (system A)Mitsubishi ElectricOkuma OSPHaasSiemens (ISO dialect)Siemens (native)LinuxCNC
One threading passLathe (mill-turn)G32 F_G32 or G33 (differs by G-code list)(not checked)G32 F_ (Q is an integer)G32 (system A), G33 (systems B and C)G33 Z_ K_G33 Z_ K_
Skip function (measurement)BothG31G31(not checked)G31 (positions in #5061 onward)G31 (positions in $AA_IM)MEAS / MEAWG38.2–G38.5
Polar coordinate interpolationLathe (mill-turn)G12.1 / G13.1G12.1 or G112 in lists 6 and 7(not checked)Lathe G112/G113G12.1 / G13.1TRANSMITNone
Cylindrical interpolationBothG07.1G07.1 or G107 in lists 6 and 7(not checked)Machining center G107G07.1TRACYLNone
Tool center point control5-axis machining centerG43.4 (FANUC 30 series)One source / referenceG43.4 / G43.5One source / referenceG169CAM post output / referenceG234(not checked)TRAORI(not checked)
Tilted working plane5-axis machining centerG68.2+G53.1CAM post output / referenceTilted working plane command (number not confirmed)One source / reference(not checked)G268 / G269(not checked)CYCLE800 (swivel cycle)(not checked)
Work coordinate systemBothG54–G59G54–G59G15 H_CAM post output / referenceG54–G59, G110–G129, G154 P_G54–G59(not checked)G54–G59.3One source / reference
Tool length compensationMachining centerG43 H_G43 H_G56 H_ (cancel with G53)CAM post output / referenceG43 H_G43 H_(not checked)G43 H_One source / reference
SubprogramBothM98 P_ (check the operator's manual for the number of digits)M98 P_ H_ L_CALL O_ / RTSCAM post output / referenceM98 P_ L_, M97M98 P_ (L_)Call by name (P is the repeat count)M98 P_ L_, o-call
Spindle gearBothDefined by the machine builder (M41–M44 in the training material)Automatic from S (up to 4 ranges)(not checked)M41 / M42M40–M45 (fixed meanings)M40 automatic, M41–M45(not checked)
MistBothSet by the machine builder(not checked)M07CAM post output / referenceM07 is shower coolant (not mist)(not checked)(not checked)M7

“(not checked)” means it could not be confirmed in public documents in this research (not that the function does not exist). No public Okuma manual was found, so the Okuma column shows what a CAM maker’s (Autodesk) post processor outputs, marked “CAM post output / reference”. The “FANUC compatible” column was checked in the Siemens ISO dialect manual (which states FANUC compatibility), the MHLW training text and similar sources, not in FANUC’s own manuals. Many of these are options, so always check your machine’s manual.

Codes whose numbers clash (check before reusing a program)

The same or very similar numbers that do completely different things on different machines or controls. Before reusing a program from another builder’s machine or another CAM post, search it for the numbers in this table (use the button at the top right to print).

NumberMeaning AMeaning BDetails
G15, G16FANUC-compatible: cancel / ON of the polar coordinate commandOkuma OSP: G15 H_ selects the work coordinate systemG54–G59
G56FANUC-compatible: work coordinate system 3Okuma OSP: tool length compensation (G56 H_)G54–G59 G43
G53FANUC-compatible: positioning in the machine coordinate systemOkuma OSP (CAM post-processor output): cancel tool length compensationG53 G43
G12, G13Haas machining centers: circular pocket millingDiffers from G12.1 and G13.1 (polar coordinate interpolation) only by the decimal pointG12.1–G13.1
G12.1, G13.1Mitsubishi Electric lathes, lists 6 and 7: polar coordinate interpolationMitsubishi Electric lathes, lists 2–5: milling interpolationG12.1–G13.1
G112, G113Haas lathes and Mitsubishi Electric: polar coordinate interpolationHaas machining centers: work coordinate systems #9 and #10G12.1–G13.1
G7, G07.1G7 in LinuxCNC: lathe diameter modeG07.1: cylindrical interpolationG07.1
G32, G33G-code system A: G32 is threadingSystems B and C, Siemens native, LinuxCNC: G33 is threadingG32
M43, M44Spindle gear ranges 3 and 4 (MHLW training material, etc.)Haas lathes: turret unclamp / clampM41–M44
M40Siemens: automatic gear selectionBeckhoff: gear range 1M41–M44
M07Mist (LinuxCNC, NIST language specification)Haas machining centers: shower coolantM07 M08
P of M98ISO dialect: program number (the upper digits are the repeat count)Siemens native: P is the repeat countM98
G68, G68.2G68: 2D coordinate rotation within the machining planeG68.2: coordinate system on a tilted plane in space (3+2 machining)G68 G68.2

The decimal point is read differently too: X1000 can mean 1000 mm or 1 mm. See the decimal point page

Frequently Asked Questions

What are the main M codes on FANUC-type controls?
In the common FANUC-type assignments, frequently used codes are M00 program stop, M01 optional stop, M02/M30 program end, M03/M04 spindle forward/reverse, M05 spindle stop, M06 tool change, M08/M09 coolant on/off, and M98/M99 subprogram call/end. Assignments differ by machine builder and model (M19, M29 and others), so your machine’s manual takes priority over the table above.
Do G90, G94, G98 and G99 mean different things on machining centers and lathes?
Yes. On a machining center, G90 is absolute programming, G94 is feed per minute and G98/G99 are initial-point and R-point return in canned cycles. On a lathe (G-code system A), G90 and G94 are the OD/ID and face cutting cycles, and G98/G99 are feed per minute and feed per revolution. G50 also becomes the maximum spindle speed setting on a lathe.
Do M codes mean different things on different machines?
They can. M codes are assigned by the machine builder, so the same number can mean different things on different machines. For example, M07 is mist in LinuxCNC and the NIST language specification, but shower coolant on Haas machining centers. Always check a real program against your machine’s manual.
What should I watch for when reusing a program from another builder’s machine?
Search it for codes whose numbers clash. For example, G56 is work coordinate system 3 on FANUC-compatible controls but tool length offset (G56 H_) on Okuma OSP. Numbers without a decimal point (X1000) can also mean 1000 mm or 1 mm depending on the machine’s setting.