CNC Lathe Programming: Lathe Operations with G-Code

CAM232 Team | April 29, 2026 | 10 min read

CNC lathe programming requires a different mindset from milling: linear movement along the Z axis, the X axis as the diameter direction, and the C axis for rotation. In this guide you will learn Fanuc-compatible CNC lathe G-Code commands, canned cycles, and how to generate them automatically with CAM232.

Lathe Coordinate System

Coordinates on a CNC lathe are defined as follows:

Note: On some controllers the X value is entered as a radius. Check your machine parameters — selecting the wrong mode will result in dimensional errors.

Basic Lathe G-Code Commands

G-CodeDescriptionExample
G0Rapid positioningG0 X100 Z5
G1Linear cuttingG1 X50 Z-30 F0.2
G2Clockwise circularG2 X60 Z-20 R10
G3Counter-clockwise circularG3 X40 Z-15 R8
G4DwellG4 P1000 (1 sec)
G20/G21Inch / Metric unitG21
G28Return to reference pointG28 U0 W0
G40/G41/G42Tool nose radius compensationG42 (right side)
G50Maximum spindle speed limitG50 S3000
G70Finish cycle (after G71/G72)G70 P10 Q20
G71OD roughing cycleG71 U1.5 R0.5
G72Face roughing cycleG72 W1 R0.5
G76Threading cycleG76 P010060 Q100 R0.05
G96Constant surface speed (CSS)G96 S180 (180 m/min)
G97Constant RPMG97 S1200
G98/G99Feed: mm/min / mm/revG99 F0.15

G96 and G97: Speed Modes

One of the most critical decisions in lathe programming is the speed mode:

G96 — Constant Surface Speed (CSS)

The controller automatically adjusts RPM as the diameter changes, keeping cutting speed constant. Ideal for a bright, consistent surface finish.

G96 S200 M3 (200 m/min constant speed, spindle forward)
G50 S4000 (max 4000 RPM limit — prevents runaway at small diameters)
G0 X80 Z2
G1 Z-50 F0.2 (RPM is calculated automatically at diameter 80mm)

G97 — Constant RPM

RPM stays fixed regardless of diameter changes. Preferred for threading, chamfering, and parting operations.

G97 S800 M3 (constant 800 RPM)
G1 X0 F0.05 (face turning, all the way to centre)

G71 — OD Roughing Cycle

G71 automatically rough-machines complex OD profiles in multiple passes. Two blocks are required for Fanuc control:

G71 U1.5 R0.5 (depth of cut 1.5mm, retract 0.5mm)
G71 P10 Q20 U0.3 W0.1 F0.25 (finish allowance: X=0.3mm, Z=0.1mm)
N10 G0 X20 (profile start)
G1 Z-10 F0.15
X35 Z-25
Z-50
N20 X80 (profile end)
G70 P10 Q20 F0.12 S220 (finish cycle)

Note: The G70 finish cycle is run after G71. G70 makes a single finishing pass over the P–Q profile using the finish parameters (F, S).

G76 — Threading Cycle

G76 automatically performs external or internal metric/inch threading. Two blocks are used in Fanuc format:

(M30×2 external thread example)
G97 S600 M3
G0 X35 Z5 (starting position)
G76 P010060 Q100 R0.05 (01: entry passes, 00: exit type, 60: thread angle; Q=min pass, R=finish allowance)
G76 X27.835 Z-28 P1082 Q350 F2.0 (X=minor diameter, P=thread height, Q=first pass, F=pitch)
ParameterDescriptionExample
P (block 1)Entry passes + exit type + angleP010060 → 1 entry, 0 exit, 60°
Q (block 1)Minimum pass depth (×0.001mm)Q100 → 0.1mm
R (block 1)Finish allowanceR0.05
X (block 2)Thread minor diameterM30×2 → X27.835
P (block 2)Thread height (×0.001mm)P1082 → 1.082mm
Q (block 2)First pass depth (×0.001mm)Q350 → 0.35mm
FPitchF2.0 → 2mm pitch

Basic Lathe Operations

OD Turning

G96 S180 G99 M3
G50 S3500
G0 X82 Z2 T0101
G1 X80 Z0 F0.3 (approach to surface)
G1 Z-100 F0.25 (cut OD)
G0 X200 Z100 (safe clearance)

Facing

G96 S200 G99 M3
G50 S4000
G0 X82 Z0.1 T0101
G1 X-1 F0.15 (face cut to centre)
G0 Z2

ID Boring

G96 S150 G99 M3
G50 S3000
G0 X24 Z2 T0303 (boring tool)
G1 Z-45 F0.1 (enlarge bore)
G0 Z5

Tool Block

At each tool change the tool number (T) and offset number (two digits) are used together:

T0101 (tool 1, offset 1 — OD turning)
T0202 (tool 2, offset 2 — facing)
T0303 (tool 3, offset 3 — ID boring)
T0404 (tool 4, offset 4 — threading)

M-Code Reference (Lathe)

M-CodeDescription
M3Spindle forward (CW)
M4Spindle reverse (CCW)
M5Spindle stop
M8Coolant on
M9Coolant off
M30Program end and rewind
M0Program stop (operator confirmation)

Automatic Lathe G-Code with CAM232

CAM232 online CAM software automatically generates G-Code from parameters for 12 lathe operations, eliminating manual G-Code writing:

Controller options include Fanuc, Siemens, Mazak, and others. G96/G97 mode, G98/G99 feed unit, and tool number are all set directly in the form.

Generate CNC Lathe G-Code Automatically

Enter parameters, download G-Code. No installation.

Try CAM232 Free

Conclusion

CNC lathe programming demands a solid foundation in the coordinate system, speed modes (G96/G97), and canned cycles (G71, G76). You can adapt the G-Code examples in this guide to your own machine, or use CAM232 to generate all these cycles automatically. When parameters like speed mode, pitch, and finish allowance are set correctly, both surface quality and tool life improve significantly.