CNC programming and alarms

G and M codes list for CNC mills and lathes (Fanuc-style controls)

Common codes for Fanuc-style mill and lathe controls; lathe codes are G-code system A. G92 threads on a Fanuc lathe but sets the coordinate system on a mill. Codes vary by control and machine builder; check your machine's programming manual.

Technical review pending. Formulas and values are cited. This notice comes down after a machinist review.

Source: FANUC mill (M series) and lathe (T series) operator's manuals, cited by control series, summarized, not reproduced. Codes vary by control and machine builder.

G codes, Fanuc-style mills and lathes (lathe: G-code system A)
CodeMill (Fanuc-style)Lathe (Fanuc-style, G-code system A)Notes
G00Rapid positioningsameRapid moves are not straight lines on every control.
G01Linear interpolation at feedsame
G02Circular interpolation, clockwisesameLathe arcs use R, or I and K.
G03Circular interpolation, counterclockwisesame
G04DwellsameDwell time format (P in milliseconds or X in seconds) depends on the control.
G17XY planenot used on a 2-axis lathe
G18ZX planedefault plane
G19YZ planenot used on a 2-axis lathe
G20Inch inputsameLathe system C uses G70.
G21Metric inputsameLathe system C uses G71.
G28Return to machine reference through an intermediate pointsameLathe programs often write G28 U0 W0 to go straight home.
G32not common on millsSingle-pass thread cuttingMill threading codes vary by control.
G40Cutter compensation cancelTool nose radius compensation cancel
G41Cutter compensation left (D word)Tool nose radius compensation left (tip number in the offset)Lathe setup in the tool nose radius compensation guide.
G42Cutter compensation rightTool nose radius compensation right
G43Tool length compensation, plus (H word)not used; the T word calls the geometry and wear offsets
G49Tool length compensation cancelnot used
G50Scaling cancelSpindle speed cap (with S) or coordinate system setting (with X and Z)Mill scaling is an option on many controls.
G53Machine coordinate positioning, one block onlysame
G54 to G59Work coordinate systems 1 to 6same, where the control has themMany lathes set the work shift with the geometry offsets instead.
G70not commonFinishing cycle after G71, G72 or G73
G71not commonStock removal in turning (along Z)
G72not a facing cycleStock removal in facing (across X)Annotated program in the G72 facing cycle example.
G73High-speed peck drilling (short chip-breaking retract)Pattern repeating cycleSame number, different job.
G74Left-hand tapping cycleFace peck drilling cycle
G75not commonOD or ID grooving cycle
G76Fine boring (oriented spindle stop, shift off the wall, retract)Multiple repetitive threading cycleLathe G76 is one block on some older controls and two blocks on Series 0i, 16i, 18i and 21i; the parameters differ between the formats.
G80Canned cycle cancelsame, on lathes with drilling cycles
G81Drilling cyclelive-tool drilling cycles vary by control
G82Drilling with a dwell at the bottom (spot drill, counterbore)varies
G83Peck drilling, full retract each peck (Q = peck depth)face drilling on lathes with live tooling, variesQ for your drill comes from the peck drilling calculator.
G84Right-hand tapping cycleface tapping on lathes with live tooling, variesFeed and RPM for the cycle come from the tapping calculator.
G85Boring, feed in and feed outvaries
G86Boring, spindle stop at the bottom, rapid outvaries
G87Back boringvaries
G89Boring with a dwell at the bottom, feed outvaries
G90Absolute programmingOD or ID turning cycle (single pass); absolute and incremental come from X and Z versus U and WThe key system A difference.
G91Incremental programmingnot used; incremental moves use U and W
G92Coordinate system settingThread cutting cycleBlock by block in the G92 threading cycle example.
G94Feed per minuteFace cutting cycle (single pass)
G95Feed per revolutionnot used; feed per rev is G99
G96Constant surface speed (some mills)Constant surface speedKeep a G50 spindle cap ahead of it on a lathe.
G97Constant RPMConstant RPMUse G97 for threading.
G98Canned cycle return to the initial pointFeed per minute
G99Canned cycle return to the R pointFeed per revolution

"same" means the lathe meaning matches the mill. "not used" or "not common" means the code has no common meaning on that machine. "varies" means it depends on the control and options. Functions are paraphrased; the programming manual for your control is the reference.

Lathe G-code systems A, B and C

Fanuc lathes run G-code system A, B or C, set by a parameter. In systems B and C, G90 and G91 are absolute and incremental, G94 and G95 are feed per minute and feed per rev, and G92 sets the coordinate system. The single-pass turning, threading and facing cycles become G77, G78 and G79 in system B, and G20, G21 and G24 in system C. Check the parameter before running a program from another lathe.

M codes, Fanuc-style mills and lathes
CodeFunctionMillLatheNotes
M00Program stopyesyesCycle start resumes.
M01Optional stopyesyesStops only with the optional stop switch on.
M02End of programyesyesMany shops use M30 instead.
M03Spindle on, clockwiseyesyes
M04Spindle on, counterclockwiseyesyes
M05Spindle stopyesyes
M06Tool changeyesnot used on most lathes; the T word indexes the turret
M08Coolant onyesyes
M09Coolant offyesyes
M19Spindle orientcommon on millsvariesBuilder-defined on many machines.
M30End of program and rewindyesyes
M98Subprogram call (P = program number)yesyes
M99Subprogram end, return to the calling programyesyes

M codes past M00 to M09, M30, M98 and M99 are mostly set by the machine builder (chuck clamp, door, bar feeder, chip conveyor). They are not listed; check the machine manual.

How to read the tables

Always read a code with the control and machine named. G92 and G76 are the classic traps: G92 threads on a Fanuc lathe in system A and shifts coordinates on a mill, and G76 is a fine boring cycle on a mill but the multiple repetitive threading cycle on a lathe. Use the filter to show only the codes that apply to one machine type.

Shop notes

  • Codes vary by control, series, options and machine builder. Check the programming manual for your machine before running a program.
  • A program from another machine gets a line-by-line check of every canned cycle block and every M code before the first run.
  • On a lathe, check the G-code system parameter (A, B or C) before trusting G90, G92 or G94 in a program.

FAQ

What is the difference between G codes and M codes?

G codes set motion and modes, such as G01 for a feed move or G90 for absolute positioning on a mill. M codes switch machine functions, such as M03 spindle on or M08 coolant on.

Is G92 the same on a mill and a lathe?

No. On a Fanuc lathe in G-code system A, G92 is the thread cutting cycle. On a mill it sets the coordinate system.

Why does G90 cut on a Fanuc lathe?

In G-code system A, G90 is the single-pass OD or ID turning cycle. Absolute and incremental moves come from X and Z versus U and W, not from G90 and G91.

What cancels a canned cycle?

G80.

What does M30 do?

It ends the program and rewinds to the start.

Why does a lathe use G99 for feed per rev and a mill use G95?

Lathe system A uses G98 and G99 for feed per minute and feed per rev. Mills use G94 and G95, and keep G98 and G99 for the canned cycle return level.

Last updated