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.
| Code | Mill (Fanuc-style) | Lathe (Fanuc-style, G-code system A) | Notes |
|---|---|---|---|
| G00 | Rapid positioning | same | Rapid moves are not straight lines on every control. |
| G01 | Linear interpolation at feed | same | |
| G02 | Circular interpolation, clockwise | same | Lathe arcs use R, or I and K. |
| G03 | Circular interpolation, counterclockwise | same | |
| G04 | Dwell | same | Dwell time format (P in milliseconds or X in seconds) depends on the control. |
| G17 | XY plane | not used on a 2-axis lathe | |
| G18 | ZX plane | default plane | |
| G19 | YZ plane | not used on a 2-axis lathe | |
| G20 | Inch input | same | Lathe system C uses G70. |
| G21 | Metric input | same | Lathe system C uses G71. |
| G28 | Return to machine reference through an intermediate point | same | Lathe programs often write G28 U0 W0 to go straight home. |
| G32 | not common on mills | Single-pass thread cutting | Mill threading codes vary by control. |
| G40 | Cutter compensation cancel | Tool nose radius compensation cancel | |
| G41 | Cutter compensation left (D word) | Tool nose radius compensation left (tip number in the offset) | Lathe setup in the tool nose radius compensation guide. |
| G42 | Cutter compensation right | Tool nose radius compensation right | |
| G43 | Tool length compensation, plus (H word) | not used; the T word calls the geometry and wear offsets | |
| G49 | Tool length compensation cancel | not used | |
| G50 | Scaling cancel | Spindle speed cap (with S) or coordinate system setting (with X and Z) | Mill scaling is an option on many controls. |
| G53 | Machine coordinate positioning, one block only | same | |
| G54 to G59 | Work coordinate systems 1 to 6 | same, where the control has them | Many lathes set the work shift with the geometry offsets instead. |
| G70 | not common | Finishing cycle after G71, G72 or G73 | |
| G71 | not common | Stock removal in turning (along Z) | |
| G72 | not a facing cycle | Stock removal in facing (across X) | Annotated program in the G72 facing cycle example. |
| G73 | High-speed peck drilling (short chip-breaking retract) | Pattern repeating cycle | Same number, different job. |
| G74 | Left-hand tapping cycle | Face peck drilling cycle | |
| G75 | not common | OD or ID grooving cycle | |
| G76 | Fine boring (oriented spindle stop, shift off the wall, retract) | Multiple repetitive threading cycle | Lathe G76 is one block on some older controls and two blocks on Series 0i, 16i, 18i and 21i; the parameters differ between the formats. |
| G80 | Canned cycle cancel | same, on lathes with drilling cycles | |
| G81 | Drilling cycle | live-tool drilling cycles vary by control | |
| G82 | Drilling with a dwell at the bottom (spot drill, counterbore) | varies | |
| G83 | Peck drilling, full retract each peck (Q = peck depth) | face drilling on lathes with live tooling, varies | Q for your drill comes from the peck drilling calculator. |
| G84 | Right-hand tapping cycle | face tapping on lathes with live tooling, varies | Feed and RPM for the cycle come from the tapping calculator. |
| G85 | Boring, feed in and feed out | varies | |
| G86 | Boring, spindle stop at the bottom, rapid out | varies | |
| G87 | Back boring | varies | |
| G89 | Boring with a dwell at the bottom, feed out | varies | |
| G90 | Absolute programming | OD or ID turning cycle (single pass); absolute and incremental come from X and Z versus U and W | The key system A difference. |
| G91 | Incremental programming | not used; incremental moves use U and W | |
| G92 | Coordinate system setting | Thread cutting cycle | Block by block in the G92 threading cycle example. |
| G94 | Feed per minute | Face cutting cycle (single pass) | |
| G95 | Feed per revolution | not used; feed per rev is G99 | |
| G96 | Constant surface speed (some mills) | Constant surface speed | Keep a G50 spindle cap ahead of it on a lathe. |
| G97 | Constant RPM | Constant RPM | Use G97 for threading. |
| G98 | Canned cycle return to the initial point | Feed per minute | |
| G99 | Canned cycle return to the R point | Feed 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.
| Code | Function | Mill | Lathe | Notes |
|---|---|---|---|---|
| M00 | Program stop | yes | yes | Cycle start resumes. |
| M01 | Optional stop | yes | yes | Stops only with the optional stop switch on. |
| M02 | End of program | yes | yes | Many shops use M30 instead. |
| M03 | Spindle on, clockwise | yes | yes | |
| M04 | Spindle on, counterclockwise | yes | yes | |
| M05 | Spindle stop | yes | yes | |
| M06 | Tool change | yes | not used on most lathes; the T word indexes the turret | |
| M08 | Coolant on | yes | yes | |
| M09 | Coolant off | yes | yes | |
| M19 | Spindle orient | common on mills | varies | Builder-defined on many machines. |
| M30 | End of program and rewind | yes | yes | |
| M98 | Subprogram call (P = program number) | yes | yes | |
| M99 | Subprogram end, return to the calling program | yes | yes |
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