The “G code for lathe” is a set of instructions that tell your CNC lathe exactly what to do, from moving the tool to making specific cuts. Mastering these basic codes will unlock precise, repeatable machining, transforming your projects from manual effort to automated accuracy. This guide breaks down essential G-code commands in a beginner-friendly way, showing you how to create simple programs for your lathe.
Unlock Your Lathe’s Potential with G-Code: A Beginner’s Guide
Ever look at your CNC lathe and wonder how it knows exactly where to move, how deep to cut, or how fast to spin? The magic behind it is G-code. Think of it as the language your machine understands. For beginners, diving into G-code can feel like learning a new, complex language. But don’t worry! It’s more about understanding a set of simple commands that, when put together, create intricate parts with incredible precision.
At Lathe Hub, we believe in making machining accessible. This guide is designed to demystify G-code for lathe users, especially those just starting out. We’ll break down the essential codes you need to know, explain how they work on a lathe, and show you how to build a basic program. By the end, you’ll feel more confident in writing your own G-code and bringing your designs to life.
What Exactly is G-Code?
G-code, also known as Geometric Code, is the standard programming language for computer-aided manufacturing (CAM). It’s a set of instructions that tells a machine tool – like your CNC lathe – what to do and how to do it. Each line of G-code is a command, often represented by a letter followed by a number.
For a lathe, G-code commands tell the machine about things like:
- Tool movement (where to go, how to get there)
 - Spindle speed (how fast the workpiece spins)
 - Coolant control (turning it on or off)
 - Feed rate (how fast the tool moves into the material)
 
While G-code is used for many CNC machines, the specific commands and their applications can vary slightly between mills and lathes. This guide focuses on the essentials for lathe operations.
Why Learn G-Code for Your Lathe?
If you have a CNC lathe, understanding G-code is essential for unlocking its full capabilities. Here’s why it’s worth your time:
- Precision and Repeatability: G-code allows you to create parts with extremely high accuracy, and you can repeat the exact same part an unlimited number of times.
 - Efficiency: Once a program is written, the lathe can run it automatically, freeing you up for other tasks or quality checks.
 - Complex Geometries: G-code enables the creation of shapes and features that would be very difficult or impossible to achieve with manual machining.
 - Problem Solving: By understanding G-code, you can troubleshoot issues in your programs more effectively.
 - Customization: You’re not limited by pre-programmed cycles; you can create custom routines tailored to your specific needs.
 
For a deeper dive into the history and standardization of G-code, the ISO 6983 standard provides a comprehensive overview, though it’s quite technical.
The Building Blocks: Essential G-Code Commands for Lathes
Let’s start with the most common and crucial G-codes you’ll encounter when programming a lathe. We’ll keep it simple, focusing on what you need to get started.
1. Preparatory and Miscellaneous Functions (G and M Codes)
G-codes typically control motion and geometry, while M-codes (Miscellaneous functions) control machine actions like turning the spindle on or off, or controlling coolant. They often work together.
G-Codes (Motion and Geometry Commands)
G-codes tell the machine how to move. For a lathe, the most common ones involve positioning the tool and defining the type of move (like straight line or circle).
Basic G-Codes to Know:
- G00: Rapid Traverse (Positioning)
This command moves the tool to a specified coordinate at the fastest possible speed without cutting. It’s used for rapid positioning between cut points, like moving from a safe height above the workpiece to the start of a cut.
Example: G00 X10.0 Y5.0 (Move to X=10, Y=5 at rapid speed)
 - G01: Linear Interpolation (Straight Line Cutting)
This command moves the tool in a straight line at a controlled feed rate. This is your go-to for most cutting operations, like turning a shaft to a specific diameter or facing off material.
Example: G01 X5.0 Z-2.0 F0.1 (Move in a straight line to X=5, Z=-2 at a feed rate of 0.1 units per revolution)
 - G02: Circular Interpolation, Clockwise
This command moves the tool in a clockwise arc. You’ll use this for chamfers, radii, or other curved features. It requires specifying the arc’s endpoint and often the center point or radius.
Example: Let’s say you want to create a radius. G02 X10.0 Z-5.0 R3.0 (Move clockwise to X=10, Z=-5 with a 3.0 radius)
 - G03: Circular Interpolation, Counter-Clockwise
Similar to G02, but the arc is in a counter-clockwise direction. Used for complementary curved features.
Example: G03 X10.0 Z-5.0 R3.0 (Move counter-clockwise to X=10, Z=-5 with a 3.0 radius)
 - G04: Dwell
This command tells the machine to pause for a specified amount of time. It’s useful for allowing vibrations to die down after a cut or before retracting the tool.
Example: G04 P1.0 (Pause for 1 second) or G04 X0.5 (Pause for 0.5 seconds)
 - G20: Inch Input
Sets the unit of measurement to inches. Most machines default to millimeters, so this is important if you’re working in imperial units.
 - G21: Metric Input
Sets the unit of measurement to millimeters. This is often the default setting.
 - G40: Tool Radius Compensation Cancel
Turns off tool radius compensation. This means the machine will follow the exact path programmed, without accounting for the tool’s cutting edge radius.
 - G41: Tool Radius Compensation Left
Activates tool radius compensation, offsetting the tool path to the left of the programmed contour. This allows you to compensate for the tool’s radius, making it easier to achieve accurate sizes, especially on complex profiles.
 - G42: Tool Radius Compensation Right
Activates tool radius compensation, offsetting the tool path to the right of the programmed contour.
 - G54-G59: Work Coordinate Systems
These codes select one of six predefined work coordinate systems. G54 is typically the most commonly used. This system defines the “zero” point of your workpiece for the current program. This is crucial for setting up your part on the lathe.
 - G71: OD Roughing Cycle
A canned cycle for roughing the outside diameter of a part.
 - G72: Facing Cycle
A canned cycle for facing off the end of a part.
 - G73: High-Speed Peck Drilling Cycle
Used for drilling deep holes by repeatedly retracting the tool to clear chips.
 - G74: Left-Hand Facing Cycle
A cycle for facing off the end of a part when the tool is on the left side (often for internal facing).
 - G75: OD Grooving Cycle
A canned cycle for cutting grooves on the outside diameter.
 - G76: Threading Cycle
A sophisticated canned cycle for cutting external threads.
 - G90: Absolute Programming
All coordinate values (X, Z) are read as absolute positions relative to the workpiece origin (G54). If you tell it to go to X10, it goes to X10, no matter where it is now.
 - G91: Incremental Programming
All coordinate values are read as relative distances from the tool’s current position. If you tell it to move X10, it moves 10 units from its current X position.
 - G94: Feed per Minute
The feed rate (F code) is interpreted in units per minute.
 - G95: Feed per Revolution
The feed rate (F code) is interpreted in units per revolution of the spindle. This is very common for turning operations.
 - G96: Constant Surface Speed (CSS)
The spindle speed is adjusted dynamically to maintain a constant surface speed at the cutting tool. This is great for achieving consistent surface finish on parts with varying diameters. Requires setting a desired CSS value.
Example: G96 S150 (Set constant surface speed to 150 units per minute)
 - G97: Constant Spindle Speed
The spindle speed is set to a fixed RPM value. Useful for drilling or when CSS is not needed.
Example: G97 S800 (Set spindle speed to 800 RPM)
 
M-Codes (Miscellaneous Function Commands)
M-codes control machine functions that aren’t directly related to tool movement. They are often specific to the machine controller, but some are universal.
Common M-Codes:
- M00: Program Stop
Shuts down the program and the spindle. The operator must manually restart the program.
 - M01: Optional Program Stop
Similar to M00, but only stops the program if the “Optional Stop” button is activated on the machine control panel.
 - M02: End of Program
Indicates the end of the program. Often performs a spindle stop and other operations. Some machines use M30.
 - M03: Spindle On, Clockwise
Starts the spindle rotating clockwise (as viewed from the front of the machine). You’ll need to specify a speed (S code) with it.
Example: M03 S1000 (Start spindle clockwise at 1000 RPM)
 - M04: Spindle On, Counter-Clockwise
Starts the spindle rotating counter-clockwise.
 - M05: Spindle Stop
Stops the spindle rotation.
 - M06: Tool Change
Initiates an automatic tool change (if your lathe has this capability).
 - M07: Mist Coolant On
Turns on mist coolant.
 - M08: Flood Coolant On
Turns on flood coolant. Essential for lubrication and chip removal during cutting.
 - M09: Coolant Off
Turns off all coolant.
 - M30: End of Program and Rewind
A more common end-of-program command than M02. It stops the spindle, turns off coolant, and rewinds the program to the beginning, ready to run again.
 
Understanding Coordinates and Axes
For a typical CNC lathe, the primary axes are X and Z. The X-axis moves radially (in and out relative to the spindle axis), and the Z-axis moves axially (along the length of the spindle axis).
X-axis: Controls the diameter. Moving in the positive X direction increases the diameter; moving in the negative X direction decreases it. For internal boring, the positive X direction moves away from the center, increasing bore diameter.
Z-axis: Controls the length. Moving in the positive Z direction moves the tool away from the chuck; moving in the negative Z direction moves it towards the chuck or into the part.
The coordinate system you use (absolute G90 or incremental G91) will determine how these positions are interpreted.
Essential G-Code Parameters
Beyond the G and M codes, you’ll use other parameters (letters followed by numbers) to define the details of each command:
- X, Y, Z: Coordinate values for the tool positioning. Y is rarely used on basic lathes but might be for live tooling.
 - I, J, K: Used with circular interpolation (G02, G03) to define the center of an arc. I is typically the X-axis offset from the start of the arc to the center, and J is the Y-axis offset. K is sometimes used for the Z-axis offset if working in 3D, but for lathed parts, I and J are most common.
 - R: Radius value for G02/G03 arcs. Some controllers prefer R, others I/J.
 - F: Feed rate. This can be specified as Feed per Minute (G94) or Feed per Revolution (G95).
 - S: Spindle speed, specified in RPM for G97 or units per minute for G96.
 - T: Tool number. Used with M06 to select a specific tool from the turret.
 - D: Cutter diameter compensation (used with G41/G42, often replacing T for compensation).
 - H: Cutter length offset (used for tool length compensation).
 
Creating Your First Lathe G-Code Program: A Step-by-Step Example
Let’s write a simple program to turn a shaft from a block of material. We’ll create a basic cylinder with a specific diameter and length.
Scenario: We want to turn a shaft to a diameter of “X1.0” and a length of “Z-2.0” from a piece of stock.
Assumptions:
- The stock is already chucked and faced.
 - We are using absolute programming (G90).
 - We want to cut in millimeters (G21) at a feed rate per revolution (G95).
 - We are using Tool 1.
 - The workpiece zero (G54) is set at the face of the part, at the spindle centerline.
 
Program Steps:
- Program Start and Setup:
 - %: (Optional, but common) Program start identifier.
 - O1001: Program number.
 - G21: Select millimeters.
 - G90: Use absolute positioning.
 - G95: Use feed per revolution.
 - G40: Cancel any previous tool radius compensation.
 - G80: Cancel any previous canned cycles.
 - T0101: Select Tool 1 and its offset (first digit is tool, second is offset register).
 - M06: Execute tool change (if automatic).
 - G54: Select Work Coordinate System 1 (your part zero).
 - G00 X50.0 Z2.0: Rapid move to clear the part, away from the chuck and above the stock’s surface. (This assumes your Z0 is at the face of the part, and X0 is on the spindle centerline. So X50 is 50mm above the centerline, and Z2 is 2mm out from the part face.)