G-code and M-code reference
The same code can mean different things on different machines: on a Fanuc mill G76 is fine boring, on a Fanuc lathe it is the multiple threading cycle. Paste a block, choose the control, and read what each word does; give the start point and see the move it makes, with an arc’s centre and radius worked out.
The table sets the common codes side by side for a Fanuc mill, a Fanuc lathe and a Siemens; picking one loads an example.
- G02
- Arc clockwise in the plane chosen by G17/G18/G19, seen from the plus end of the third axis. Centre by I, J, K from the start point, or radius R (negative over 180°). A third-axis word makes a helix.
- X30.
- X end point.
- Y30.
- Y end point.
- I15.
- Arc centre, X distance from the start point.
- J-5.
- Arc centre, Y distance from the start point.
- F200.
- Feed, mm/min (G94).
- Move
- Arc clockwise
- To
- X30.000 Y30.000
- Length
- 24.836
- Radius
- 15.811
- Centre
- X25.000 Y15.000
- Turns through
- 90.000°
How it’s calculated
| Code | Fanuc mill | Fanuc lathe (system A) | Siemens |
|---|---|---|---|
| G00Motion | Rapid move to the point. A parameter chooses a straight path or each axis at its own rapid rate, so never assume a straight line near the part. | Rapid move to the point. A parameter chooses a straight path or each axis at its own rapid rate. | Rapid move to the point: a straight line with RTLION, each axis on its own with RTLIOF. Not for cutting. |
| G01Motion | Straight cut to the point at feed F. | Straight cut to the point at feed F (per revolution under G99). | Straight cut to the point at feed F. |
| G02Motion | Arc clockwise in the plane chosen by G17/G18/G19, seen from the plus end of the third axis. Centre by I, J, K from the start point, or radius R (negative over 180°). A third-axis word makes a helix. | Arc clockwise in the ZX plane. Centre by I (in radius) and K from the start point, or radius R. | Arc clockwise. Centre by I, J, K from the start point (or =AC() from the zero), or radius CR= (negative over 180°). |
| G03Motion | Arc counter-clockwise; centre and radius as for G02. | Arc counter-clockwise in the ZX plane; centre and radius as for G02. | Arc counter-clockwise; centre and radius as for G2. |
| G04Motion | Dwell: X in seconds (decimal point allowed), or P in the least increment, so P1000 is 1 s on a 0.001 s system. | Dwell: X or U in seconds, or P in the least increment. | Dwell: F in seconds, or S in spindle revolutions. It must be alone in its block. |
| G09Motion | Exact stop for this block only: the axes stop dead at its end before the next block starts. | Exact stop for this block only. | Exact stop for this block only (G9). |
| G28Machine | Return to the reference position through an intermediate point: the X/Y/Z given are that point. G91 G28 Z0 goes straight up from where it is. | Return to the reference position through the point given (U0 W0 for straight from here). | — |
| G30Machine | Return to the 2nd (P2), 3rd or 4th reference position, through the point given. Often the tool-change position. | Return to the 2nd, 3rd or 4th reference position. | — |
| G31Motion | Skip: feed towards the point and stop where the skip signal (a probe touching) comes in. | Skip: feed towards the point and stop on the skip signal. | — |
| G32Motion | — | Thread cutting, constant lead: F is the lead. One pass per block; G92 and G76 build the passes for you. | — |
| G33Motion | Thread cutting, constant lead: F is the lead. | — | Thread cutting, constant lead: the lead goes in I, J or K for the axis it runs along. |
| G17Plane | Work in the XY plane: arcs, cutter compensation and drilling cycles use it. The usual default on a mill. | Work in the XY plane. | Work in the XY plane; the tool length acts along Z. |
| G18Plane | Work in the ZX plane. | Work in the ZX plane: the lathe's own plane. | Work in the ZX plane; the plane for turning. |
| G19Plane | Work in the YZ plane. | Work in the YZ plane (with a Y axis). | Work in the YZ plane. |
| G20Units and dimensions | Inch input. Put it at the start of the program, alone, before anything moves. | Inch input (G70 in G code system C). | — |
| G21Units and dimensions | Metric input. | Metric input (G71 in G code system C). | — |
| G70Cycles | — | Finishing cycle: runs the profile between blocks P and Q once, after G71, G72 or G73 has roughed it. | Inch, for lengths only (geometry); feeds stay as they were. G700 makes feeds inch too. |
| G71Cycles | — | Stock removal in turning: roughs the profile between blocks P and Q along Z, U the depth a pass, R the retract; a second G71 carries the finishing allowances. | Metric, for lengths only (geometry). G710 makes feeds metric too. |
| G72Cycles | — | Stock removal in facing: as G71, the passes across the face along X. | — |
| G700Units and dimensions | — | — | Inch for every length, feeds included. |
| G710Units and dimensions | — | — | Metric for every length, feeds included. |
| G90Units and dimensions | Absolute: X, Y, Z are positions from the work zero. Modal until G91. | Turning cycle (OD or ID), straight or taper: one roughing pass per block. Absolute and incremental come from X/Z against U/W instead. | Absolute: positions from the work zero. One axis can be made incremental with =IC(). |
| G91Units and dimensions | Incremental: X, Y, Z are distances from where the tool is. | — | Incremental: distances from where the tool is. One axis can be made absolute with =AC(). |
| G50Coordinates and offsets | Scaling cancel. | Set the coordinate system to the X and Z given, or with S, clamp the spindle's top speed (vital before G96). | — |
| G52Coordinates and offsets | Local coordinate system: shifts the zero by the amount given inside the current work offset. G52 X0 Y0 cancels it. | Local coordinate system shift. | — |
| G53Coordinates and offsets | Machine coordinates for this block only: the positions given are from the machine zero. | Machine coordinates for this block only. | Suppresses the settable and programmable zero offsets for this block. G153 and SUPA suppress more. |
| G54Coordinates and offsets | Work offset 1 (G55 to G59 are 2 to 6; G54.1 P1 to P48 or more where fitted). | Work offset 1 (G55 to G59 are 2 to 6). | Settable zero offset 1 (G55 to G57 are 2 to 4, G505 to G599 the rest; G500 cancels). |
| G500Coordinates and offsets | — | — | Cancels the settable zero offset (G54 to G599). |
| G68Coordinates and offsets | Rotate the coordinate system by R degrees about the point given; G69 cancels. | Mirror image for double turrets; G69 cancels. (G68.1 is rotation on a lathe.) | — |
| G92Coordinates and offsets | Set the work coordinate system so the tool is at the position given (or with S, clamp the spindle speed). Prefer G54 to G59. | Threading cycle: one threading pass per block, Z the end, F the lead. | — |
| G40Tool compensation | Cutter radius compensation off. | Tool nose radius compensation off. | Tool radius compensation off. |
| G41Tool compensation | Cutter radius compensation, tool left of the path looking along the feed; D is the offset number. Start it on a straight move. | Tool nose radius compensation, tool left of the path; the nose radius and tip direction come with the T code's offset. | Tool radius compensation, tool left of the contour; the radius comes from the active D. |
| G42Tool compensation | Cutter radius compensation, tool right of the path. | Tool nose radius compensation, tool right of the path. | Tool radius compensation, tool right of the contour. |
| G43Tool compensation | Tool length compensation plus: adds offset H to Z moves. G44 subtracts; G49 cancels. | — | No G43: the tool length applies with the tool (T) and its cutting edge (D); D0 cancels it. |
| G49Tool compensation | Tool length compensation cancel. | — | — |
| G73Cycles | High-speed peck drilling: pecks of Q, backing off only a little (set by parameter) to break the chip. | Pattern repeating cycle: repeats the profile between P and Q, offset each time, for forged or cast blanks. | — |
| G74Cycles | Left-hand tapping cycle: spindle reversed in, forward out. | End-face peck cycle along Z: peck drilling on the centre line, or grooving on the face. | Approach the reference point. |
| G75Cycles | — | Peck cycle along X: OD or ID grooving (Fanuc calls it the diameter drilling cycle). | Approach a fixed point (FP= picks which). |
| G76Cycles | Fine boring: at the bottom the spindle orients and the bar shifts off the wall by Q, so it comes out without marking the bore. | Multiple threading cycle: works out every pass of a thread from the depths and angle given (two blocks). | — |
| G80Cycles | Cancel the canned cycle. | Cancel the drilling cycle. | No G80: a cycle made modal with MCALL is cancelled by MCALL alone. |
| G81Cycles | Drilling cycle: rapid to R, feed to Z, rapid out. Modal: each following X/Y drills another hole. | — | CYCLE81 is the drilling cycle. |
| G82Cycles | Drilling with a dwell P at the bottom, for counterbores and spot faces. | — | CYCLE82 drills with a dwell at the bottom. |
| G83Cycles | Peck drilling: pecks of Q, back out to R after each one to clear the chips. | Face drilling cycle (on a lathe with live tooling). | CYCLE83 is deep-hole drilling with chip breaking or full retract. |
| G84Cycles | Tapping cycle: feed in, spindle reverses at the bottom, feed out. Rigid with M29 (or a parameter); F is lead × rpm under G94. | Face tapping cycle (live tooling). | CYCLE84 taps rigidly; CYCLE840 with a compensating chuck. |
| G85Cycles | Boring cycle: feed in, feed out. | Face boring cycle (live tooling). | CYCLE85 to CYCLE89 are the boring cycles. |
| G98Cycles | Canned cycle returns to the initial level between holes (clear of clamps). | Feed per minute. | — |
| G99Cycles | Canned cycle returns to the R level between holes (quicker). | Feed per revolution: F in mm/rev. The usual lathe default. | — |
| G94Feed | Feed per minute: F in mm/min. | End-face turning cycle: one facing pass per block. | Feed per minute: F in mm/min. |
| G95Feed | Feed per revolution: F in mm/rev. | — | Feed per revolution: F in mm/rev. |
| G96Spindle | Constant surface speed: S in m/min; the rpm follows the diameter. Clamp the top speed first (G92 S). | Constant surface speed: S in m/min; the rpm rises as the diameter falls. Clamp it first with G50 S. | Constant cutting rate: S in m/min, feed per revolution as G95. Clamp the top speed with LIMS=. |
| G97Spindle | Constant surface speed off: S in rpm. | Constant surface speed off: S in rpm (drilling and threading on centre). | Constant cutting rate off: S in rpm. |
| G25Spindle | Spindle speed fluctuation detection off (G26 on). | Spindle speed fluctuation detection off (G26 on). | With S: the lowest spindle speed allowed. With axes: the lower corner of the working area. G26 sets the upper. |
| G26Spindle | Spindle speed fluctuation detection on. | Spindle speed fluctuation detection on. | With S: the highest spindle speed allowed. With axes: the upper corner of the working area. |
| M00Program flow | Program stop: everything halts after the block until cycle start; modal states are kept. | Program stop until cycle start. | Programmed stop (M0). |
| M01Program flow | Optional stop: stops only when the optional stop switch is on. | Optional stop. | Optional stop (M1). |
| M02Program flow | End of program; resets. Whether it goes back to the start is a parameter. | End of program. | End of main program (as M30). |
| M30Program flow | End of program, back to the start. | End of program, back to the start. | End of main program (as M2). |
| M98Program flow | Call subprogram P (the program number); the control handles it, not the machine. | Call subprogram P. | No M98: call a subprogram by its name, or L with its number. |
| M99Program flow | End of subprogram: back to the block after the call (in a main program, back to its start). | End of subprogram. | No M99: M17 (or RET) ends a subprogram. |
| M17Program flow | — | — | End of subprogram. |
| M03Spindle | Set by the machine builder, not the control: spindle forward (clockwise) on nearly every machine. | Set by the machine builder, not the control: spindle forward on nearly every lathe. | Spindle clockwise (M3). |
| M04Spindle | Set by the machine builder, not the control: spindle reverse on nearly every machine. | Set by the machine builder, not the control: spindle reverse on nearly every lathe. | Spindle counter-clockwise (M4). |
| M05Spindle | Set by the machine builder, not the control: spindle stop on nearly every machine. | Set by the machine builder, not the control: spindle stop on nearly every lathe. | Spindle stop (M5). |
| M06Machine | Set by the machine builder, not the control: tool change on most machining centres, to the tool called by T. | — | Tool change (M6), the default setting. |
| M08Machine | Set by the machine builder, not the control: coolant on, on most machines (M09 off). | Set by the machine builder, not the control: coolant on, on most lathes (M09 off). | Set by the machine builder, not the control: coolant on, on most machines. |
| M19Spindle | Set by the machine builder, not the control: spindle orientation on many machines. | — | Spindle positioning (M19). |
| M29Spindle | Rigid tapping mode, before G84: M29 unless parameter No. 5210 sets another code. | Rigid tapping mode: M29 unless parameter No. 5210 sets another code. | — |
Why does my M code do something else on this machine?
A Fanuc control acts on only a handful of M codes itself: program stop, optional stop, the two program ends and the subprogram call and return. Every other M code, spindle and coolant included, is wired up by the machine builder, so the machine’s own manual is the one to trust. Siemens predefines a few more, the spindle and tool change among them.