Lathe G_M Codes

Back Home Up Next

Safety & Access Agreement






Regardless of manufacturer, control, software, or off-line (CAM) programming system, nearly all CNC machines use preparatory (G) and miscellaneous function (M) codes, and a combination of defining parameters (called words), to execute the operations required to produce parts.  Most G codes direct the motion of the machine in some manner, while M codes control ancillary functions such as spindle on / off, coolant on / off, tool changes, etc.  It is not essential for the engineering student to memorize these commands, as you would expect of the CNC machinist or programmer, but listing the more commonly used codes here, will allow an engineer, utilizing a CAM software package off-line, to understand the relationship to the executed machine codes.   Each code is listed along with a brief description including the parameters that may be used in conjunction with the command.


Common Lathe G-Codes


*G00   Rapid linear move. [X,Z,U,W] Moves the machine at the fastest rate possible to the X,Z location specified or incrementally U (X) W(Z) distance.

  G01   Linear feed move [X,Z,U,W,F] Moves the machine at the specified feed rate (F) to the X,Z location specified or incrementally U (X) W(Z) distance.

  G02   Circular interpolation; CW. [X,Z,U,W,F,R (or I,K)] Moves the machine, in a clockwise circular path to the X,Z, location (or incrementally by U,W) with radius R, or with a center point defined relative to the start point in the X,& Z axis by I, & K respectively.

  G03   Circular interpolation; CCW. [X,Z,U,W,F,R (or I,K)] Same as G02, but opposite direction of movement.


  G28   Machine home.  Causes the machine to return to it’s X0,Z0 position at a rapid rate.


*G40   Tool nose compensation, CANCEL.  [X,Z,U,W,I,K,F] Cancels the G41 or G42 Cutter compensation listed below. Causes a feed move to X and/or Z at feed rate F (or at modal feed F, if not specified).  The distance of the move must be greater than the radius of the tool.

  G41   Tool nose compensation, LEFT.  [X,Z,U,W,D,F] Looking from the spindle toward the part, G41 offsets the position of the tool left of the programmed tool path by the value stored in the offsets register position called by the D word.  Causes a feed move from the current position to the compensated position specified by X,Y, at feed F (or at modal feed F if not specified).  The distance of this move must be greater than the radius of the tool.

  G42   Tool nose compensation, RIGHT.  Same as G41 above except that the tool is compensated to the right of the programmed tool path.

            NOTE:  Cutter compensation may be accomplished at the machine, through the toolpath generated by the CAM program, or both.                

  G50   Spindle speed clamp.    Specifies the maximum RPM the spindle can run during constant surface speed operation.

  G70   Finishing Cycle 

  G71   OD / ID stock removal (roughing) cycle

  G72   End Face stock removal (roughing) cycle

  G76   Thread cutting cycle

(G70 thru G76 are rarely used for CAM processes) 

*G80   Canned cycle cancel.  This command cancels any active “canned cycle” commands below.

  G81   Drill cycle.  [X,Y,Z,R,F] Will drill a hole to Z depth at a location defined by X, Y, at feed rate F.  R is the rapid plane, a Z axis dimension “above the part” that denotes the point where the machine switches from rapid rate to feed rate.  Will continue to drill the same hole profile at subsequent X,Y locations until cancelled by G80.

  G82   Spot drill / Counterbore cycle. [X,Y,Z,R,F,P] Similar to above, but adds the P word to establish a dwell, or pause at the end of the Z axis stroke.

  G83   Deep Hole Peck drill cycle.  [X,Y,Z,R,Q,(or I,J,K),R,F,P] Drills the hole in a series of steps, or pecks, at either a constant peck depth Q, or at a decreasing peck depth where I is the initial peck depth, J is the amount of decrease per peck and K is the minimum peck depth.  Other parameters are as for other drill cycles.

  G84   Rigid tap cycle (right hand threads).  [X,Y,Z,J,R,F]  Precisely coordinates the rotation of the spindle with the feed rate of the Z axis for use with right hand taps.  The J word is a multiplying factor for the retract speed.  Feed rate is computed by multiplying rpm by thread pitch and is carried to 3 decimal places.

*G90   Absolute Programming Mode  All X,Y,Z coordinates determined from a single from a single origin.

  G91   Incremental Programming Mode  Next X,Y,Z, coordinates are determined from current location.

  G96   Constant Surface Speed ON .  Constantly adjusts spindle RPM to maintain a chosen SFPM regardless of cut diameter.

  G97   Constant Surface Speed OFF.  Maintains static spindle RPM regardless of cut diameter.          

  G98   Canned cycle initial point return.  Traverses from hole to hole at the initial point Z height, typically 1.0 inch.

  G99   Canned cycle rapid (R) plane return.  Traverses from hole to at the  rapid plane Z height, typically 0.1 inch.


Common Lathe M-Codes


  M00   Program stop.  stops the machine, requiring the operator to restart the program to continue.

  M01   Optional stop.  stops the machine as above only when the optional stop button has been pressed prior to this command in the program.

  M03   Spindle start, CW. [S] Starts the spindle in a clockwise direction, at the RPM specified by the S word accompanying the code.

  M04   Spindle start, CCW. [S] Similar to above, but rotation is reversed.

  M05   Spindle stop.

  M08   Coolant on. 

  M09   Coolant off.

  M19   Spindle orientation.

  M30   Program stop and rewind. to program start

  M97   Local subroutine call. [N] Causes the program to skip to a subprogram contained inside the current program at line number N.

  M98   Subprogram call [P,L] The program will call another program number, specified by the P word, and execute it L times.

  M99   Subprogram return.  Contained at the end of the subprogram (or subroutine) will return the control to the main program.

(only one M Code can be used per line and will be executed after all other operations specified in the line)


All products and services described and / or mentioned herein are registered trademarks, registered servicemarks, trademarks, or servicemarks of their respective companies.

Questions or problems regarding this web site should be directed to the webmaster
Copyright © 2006 The UAH College of Engineering. All rights reserved.
Last modified: Thursday February 03, 2005.