Quick Summary: Master essential G and M codes for your lathe with our beginner-friendly charts. These codes control basic movements and machine functions, making your machining tasks easier and more precise. Learn the codes that matter most to get started with confidence in your workshop.
Welcome to Lathe Hub! Ever found yourself staring at a CNC lathe, wondering how to tell it what to do? It can seem a bit like learning a new language, with all those “G” and “M” codes. But don’t worry, it’s much simpler than you think!
These codes are the secret handshake between you and your machine, telling it everything from where to move to when to spin the spindle. Understanding the basics of G and M codes is like gaining a superpower for your lathe. It opens up a world of precise cuts, repeatable operations, and exciting projects.
We’ll break down the most common and useful G and M codes specifically for lathes in a way that’s easy to grasp. Get ready to feel more confident and in control of your machining. Let’s dive in and demystify these essential commands!
Understanding G and M Codes: Your Lathe’s Command Language
Think of G and M codes as instructions for your CNC lathe. They are part of a programming language called G-code, which is standardized but can have variations between different machine manufacturers.
- G-Codes (Preparatory Codes): These codes prepare the machine for a specific type of action. They tell the lathe how to move or perform an operation. For example, a G-code might tell the machine to move in a straight line (a rapid move) or to cut along a specific path.
- M-Codes (Miscellaneous Codes): These codes control machine functions that aren’t related to motion. They turn things on or off, like the spindle, coolant, or the tool changer.
For beginners, learning the most frequently used codes will dramatically improve your ability to operate and program your lathe. We’ll focus on these core commands to get you up and running.
Essential G Codes for Lathe Operations
G-codes are all about movement and geometry. Here are some of the most important ones you’ll encounter when working with most metal lathes.
1. Movement Codes
These codes tell the lathe how to move the cutting tool relative to the workpiece.
G00: Rapid Traverse
This code instructs the machine to move the tool at its maximum possible speed from its current position to a new, specified coordinate. It’s used for non-cutting moves, like positioning the tool before starting a cut or moving between features. Think of it as a quick “get there” command.
When to use it: Positioning the tool quickly before a cutting operation, moving to a safe retracted position.
G01: Linear Interpolation (Feed Move)
This is your workhorse for cutting. G01 tells the machine to move the tool in a straight line at a controlled feed rate. This is what you use for most turning, facing, and grooving operations where a specific speed is needed for a clean cut.
You’ll need to specify the destination coordinates (X and Z) and the feed rate (F).
When to use it: All straight-line cuts, facing operations, turning cylindrical shapes, cutting threads.
G02: Circular Interpolation, Clockwise
This code instructs the machine to move the tool in a circular path, moving clockwise from the start point to the end point. It’s used for creating rounded features like fillets or arcs with a clockwise direction.
You’ll typically define the end point (X, Z) and the center of the arc using an I or J code (relative to the start point) or an R code (radius).
When to use it: Creating concave or convex rounded corners, cutting circular profiles clockwise.
G03: Circular Interpolation, Counterclockwise
Similar to G02, but this code moves the tool in a circular path counterclockwise. It’s used for arcs and rounded features in the opposite direction.
When to use it: Creating concave or convex rounded corners, cutting circular profiles counterclockwise.
2. Plane and System Codes
These codes set up how the machine interprets coordinates and performs operations.
G17, G18, G19: Plane Selection
These codes select the active plane for circular interpolation (G02, G03). For lathes, you’ll primarily work in:
- NOT USED ON LATHE (Usually for Milling): G17 selects the XY plane.
- NOT USED ON LATHE (Usually for Milling): G18 selects the XZ plane.
- NOT USED ON LATHE (Usually for Milling): G19 selects the YZ plane.
On a standard lathe, you’re typically working in the XZ plane, so these often don’t need to be explicitly programmed unless your control requires it. You’ll usually find the lathe operates in the XZ plane by default for turning operations.
G40, G41, G42: Cutter Compensation
These codes manage how the machine accounts for the radius of the cutting tool. This is a more advanced topic, but understanding it is crucial for accurate machining of profiles.
- G40: Cutter Compensation Cancel: Turns off cutter compensation. The machine will follow the programmed path exactly, as if the tool tip were a point.
- G41: Cutter Compensation Left: Activates cutter compensation, offsetting the tool path to the left of the programmed contour (when viewed in the direction of cut). This is used when the tool approaches a corner from “above” or “ahead.”
- G42: Cutter Compensation Right: Activates cutter compensation, offsetting the tool path to the right of the programmed contour (when viewed in the direction of cut). This is used when the tool approaches a corner from “below” or “behind.”
Why it’s important: If you don’t use cutter compensation, your part dimensions will be off by the radius of your tool insert. G41/G42 ensures your part matches the drawing.
3. Lathe-Specific G Codes
These codes are common on CNC lathes and control specific lathe functions.
G90: Absolute Programming
In absolute mode, all coordinate values (X, Z) are measured from the program zero (or workpiece origin). If you want to move to X50 Z20, the machine goes to exactly X50 and Z20 from the origin.
When to use it: When you want to specify exact locations for cuts and movements. Most programming is done in absolute mode.
G91: Incremental Programming
In incremental mode, all coordinate values are measured from the tool’s current position. If you’re at X50 Z20 and you program an X5 Z2 move, the tool will move 5 units in the X direction and 2 units in the Z direction from its current spot, ending up at X55 Z22.
When to use it: For repeating patterns or relative movements where the exact absolute position isn’t as critical as the distance moved.
G94: Inch per Minute Feed Rate
This sets the feed rate (with the F word) to be in inches per minute. This is common in shops that work with imperial measurements.
G95: Inch per Revolution Feed Rate
This sets the feed rate to be in inches per revolution of the spindle. This is often preferred for turning operations because it results in a constant chip thickness regardless of the spindle speed, leading to a better surface finish.
G96: Constant Surface Speed (CSS)
This is a crucial one for lathes! G96 tells the machine to maintain a constant surface speed (SFM or meters/minute) for the cutting tool. As the diameter of the workpiece changes (e.g., during facing operations), the spindle RPM automatically adjusts up or down to keep the cutting speed constant. This leads to a more consistent surface finish and better tool life.
You’ll need to specify the desired surface speed value after G96 (e.g., G96 S500 activates CSS at 500 SFM).
When to use it: Most turning and facing operations to achieve consistent surface finish and tool life.
G97: Constant Spindle Speed
This code deactivates Constant Surface Speed (G96) and tells the machine to rotate the spindle at a fixed RPM (specified with an S word). The surface speed will vary as the diameter changes.
When to use it: For threading operations, or when you need total control over spindle speed and surface finish isn’t the primary concern.
G98: Feed per Minute
This sets the feed rate (with the F word) to be in units per minute. Typically used in conjunction with G94 if using imperial units, or G21 (metric) if using metric units and wanting per-minute feed.
G99: Feed per Revolution
This sets the feed rate (with the F word) to be in units per revolution of the spindle. Typically used in conjunction with G95 if using imperial units, or G21 (metric) if using metric units and wanting per-revolution feed.
4. Lathe Turning Cycle Codes
These codes simplify common turning operations.
G71: OD (Outside Diameter) Roughing Cycle
This is a very common G-code for face and OD roughing. It allows you to program a stock profile with a few moves, and then G71 will automatically repeat those profiling moves while progressively reducing the workpiece diameter to a final size. It reduces the amount of code needed for roughing.
Requires parameters like final diameter, roughing depth of cut, stock to leave for finishing, and starting/ending points.
When to use it: Rapidly removing material from the outside diameter of a part.
G72: Facing Cycle
Similar to G71, but designed specifically for facing operations (cutting from the center outwards or vice-versa). It allows you to rough the face of the workpiece efficiently.
Requires parameters like final depth of cut, stock to leave for finishing, and starting/ending points.
When to use it: Machining the end face of a part to a specific dimension.
G73: High-Speed Peck Drilling Cycle (Less common on typical lathes, more on mills but sometimes available)
Used for drilling deep holes. It retracts the tool periodically to clear chips, allowing deeper drilling without clogging.
G74: Left-Hand Facing Cycle (or Peck Drilling Cycle for Facing)
Can be used for facing operations from the outside-in, or as a peck drilling cycle for drilling from the face towards the chuck.
G75: OD Grooving Cycle
This code is specifically for cutting grooves on the outside diameter. It allows you to rough out a groove by rapidly moving in and out.
G76: Threading Cycle
This is a multi-line code that automates the process of cutting screw threads. You program the start point, thread specifications (pitch, diameter, length), and the number of passes. The machine then makes multiple shallow passes, gradually cutting the thread to the correct size and form.
When to use it: Cutting internal or external threads efficiently and accurately.
Common M Codes for Lathe Control
M-codes are the “miscellaneous” commands that control auxiliary machine functions. These are essential for running your lathe.
1. Spindle Control
These codes manage the rotation of the workpiece.
M03: Spindle On, Clockwise
Starts the spindle rotating in a clockwise direction when viewed from the spindle nose. You’ll usually specify the speed (S value) on the same line or a preceding line.
Example: M03 S1500 (Spindle on, clockwise at 1500 RPM)
When to use it: To start the workpiece rotating before cutting.
M04: Spindle On, Counterclockwise
Starts the spindle rotating in a counterclockwise direction. This is less common for standard turning but might be used for specific operations.
Example: M04 S1500 (Spindle on, counterclockwise at 1500 RPM)
M05: Spindle Stop
Stops the spindle rotation. This is used when you need to stop the workpiece to change tools, make measurements, or end a program segment.
When to use it: To stop the workpiece rotation. Always used after M03 or M04.
2. Coolant Control
Cooling and lubrication are vital for clean cuts and tool longevity.
M07: Mist Coolant On
Turns on mist coolant. This sprays a fine mist of coolant onto the cutting area.
When to use it: For operations where a light application of coolant is sufficient.
M08: Flood Coolant On
Turns on flood coolant. This delivers a steady flow of coolant to the cutting tool and workpiece. This is the most common coolant command for metalworking.
When to use it: Most metal cutting operations benefit from flood coolant.
M09: Coolant Off
Turns off all coolant (both mist and flood). This is used when you no longer need coolant for the current operation or at the end of the program.
3. Program Control and Tool Changes
These codes manage the program flow and tool management.
M00: Program Stop (Indefinite)
This code halts the program execution completely. The machine will stop, and an operator must manually press a “cycle start” button to resume the program. Used for manual inspection or intervention.
When to use it: To check a dimension, deburr a part, or perform a manual step before continuing.
M01: Optional Program Stop
Similar to M00, but its execution depends on an “optional stop” switch on the machine control panel. If the switch is on, the program stops; if it’s off, the program continues. Useful for optional checks.
M06: Tool Change
This command initiates an automatic tool change. The machine will typically retract the tool, position to the tool change location, index to the correct turret station, and then position the new tool into the cutting position.
When to use it: When switching from one cutting tool to another during a part program.
M30: Program End and Rewind
This code signals the end of the program. It stops the spindle, turns off coolant, and rewinds the program to the beginning so it can be run again without manually reloading it. This is the standard way to end a CNC program.
When to use it: At the very end of your part program.
Putting It All Together: A Simple Example
Let’s imagine a very basic program to turn down a shaft from a diameter of 1.000″ to 0.875″ over a length of 2 inches, using a simple facing cut first. We’ll use G71 for OD roughing.
Here’s a simplified example (specific parameters may vary by controller):
%
O0001 (SIMPLE TURN)
(TOOL 1 - OD ROUGHING)
(TOOL 2 - FINISH TOOL)G21 G99 G40 (Metric, Feed per Rev, Cancel Comp)
(SETUP POINT)
G00 G54 X20. Z2. (Rapid to safe position)(FACING OPERATION - using G01 for simplicity, could use G72)
M08 (Coolant On)
G00 X1.0 Z0.1 (Rapid to start position on face)
G96 S500 (Constant Surface Speed 500 SFM)
G01 Z0. F0.01 (Face off 0.1" quickly)
G00 X1.0 Z0.2 (Rapid back to clearance)(ROUGHING OPERATION - G71)
(We want to turn from X1.0 to X0.875 over Z0. to Z-2.0)
(Stock to leave: OD = 0.010, Face = 0.005)
(Roughing depth of cut: X = 0.100, Z = not applicable for this line)G00 X1.1 Z0.1 (Rapid to start point above finished diameter




