CNC turning programming is the language you use to drive a 2-axis lathe: the spindle rotates the workpiece while a single-point tool moves in X (radial) and Z (axial) to remove material.
This guide uses Fanuc-style syntax (the most common dialect — Haas, Mazak, Siemens 828D Turn etc. are all near-identical at the basic level).
1. The Lathe Coordinate System
A lathe has two axes: X (across the bed, toward/away from the spindle centreline) and Z (along the bed, toward/away from the chuck).
Things to understand right now
- +X is OUT (away from the centreline). −X moves toward the centreline.
- +Z is RIGHT (away from the chuck). −Z is toward the chuck.
- The origin (X0, Z0) is set by you, normally at the finished face of the part on the spindle centreline — so X0 means "on centre", and Z0 means "on the front face".
- X is in DIAMETER, not radius.
G01 X40means cut to a 40 mm diameter (i.e. 20 mm from centre). This trips up everyone the first time.
2. The Anatomy of a Block
A "block" is one line of the program. Each block is built from words: a letter address followed by a number.
N20 G01 X25.0 Z-30.0 F0.15 ;
│ │ │ │ │ └── comment terminator (some controls)
│ │ │ │ └── F = feed (mm/rev with G95)
│ │ │ └── Z target
│ │ └── X target (diameter)
│ └── G code (motion type)
└── line / sequence number (optional)
Common addresses:
| Letter | Meaning |
|---|---|
| N | Sequence (line) number |
| G | Preparatory function — what kind of motion |
| M | Miscellaneous — spindle, coolant, program control |
| X, Z | Target coordinates (X = diameter) |
| U, W | Incremental X, Z |
| I, K | Arc centre offsets relative to start point |
| R | Arc radius (alternative to I/K) |
| F | Feed rate |
| S | Spindle speed |
| T | Tool number + offset (e.g. T0101) |
3. Modal vs Non-Modal Codes
A modal code stays active until cancelled by another code in the same group. A non-modal code only acts on its own line.
G01 X20.0 Z0.0 F0.2 ; G01 turns ON, feed = 0.2 mm/rev
X20.0 Z-50.0 ; G01 still active, no need to repeat
G00 X100.0 Z100.0 ; modal change → now in rapid mode
Knowing this is the difference between a tidy 30-line program and a repetitive 200-line one.
4. The Essential G-Code Reference (Turning)
Motion (Group 01)
| Code | What it does |
|---|---|
| G00 | Rapid traverse (no cutting). Use to move between cuts. |
| G01 | Linear feed (cutting). Straight-line cut at F. |
| G02 | Circular feed, clockwise (looking at the print). |
| G03 | Circular feed, counter-clockwise. |
Plane / units / mode
| Code | What it does |
|---|---|
| G20 / G21 | Inch / metric units |
| G90 | Absolute positioning (X, Z = position from origin) |
| G91 | Incremental positioning (use U, W on most lathes instead) |
| G94 | Feed per minute (mm/min) |
| G95 | Feed per revolution (mm/rev) — standard for turning |
| G96 | Constant Surface Speed (CSS) — S is m/min, RPM auto-adjusts as X changes |
| G97 | Constant RPM — S is rev/min |
| G50 | Maximum spindle clamp (used with G96) |
Tool nose radius compensation
| Code | What it does |
|---|---|
| G40 | Cancel nose-radius comp |
| G41 | Comp left of toolpath (inside diameters, back-turning) |
| G42 | Comp right of toolpath (most outside turning) |
Canned cycles (the workhorses)
| Code | What it does |
|---|---|
| G70 | Finishing cycle (uses the contour from a G71/72/73 block range) |
| G71 | Stock removal — roughing along Z (multiple Z-passes) |
| G72 | Stock removal — roughing along X (facing roughing) |
| G73 | Pattern repeating (for forgings/castings already near shape) |
| G74 | Peck drilling on centreline (along Z) |
| G75 | Grooving (along X) |
| G76 | Threading (multi-pass automatic) |
| G92 | Single-pass threading cycle (older, manual passes) |
| G94 | Box (face) turning cycle |
M-codes you must know
| Code | Meaning |
|---|---|
| M03 | Spindle ON, clockwise |
| M04 | Spindle ON, counter-clockwise |
| M05 | Spindle stop |
| M08 / M09 | Coolant ON / OFF |
| M30 | Program end + rewind |
| M00 | Program stop (operator must press cycle start to continue) |
| M01 | Optional stop |
5. Spindle Speed: G96 vs G97
G50 S2500 ; clamp max RPM at 2500 (safety for chuck/part)
G96 S180 M03 ; CSS: spindle auto-adjusts so the cutting speed at
; the current X is 180 m/min. As X gets smaller
; (turning down) the RPM ramps up.
versus
G97 S1200 M03 ; constant 1200 RPM — required for drilling, threading,
; or any cut where surface speed changes don't matter.
Rule of thumb: use G96 for turning and facing on the OD (gives a constant surface finish across the diameter), use G97 for drilling, threading, parting near centre.
6. Tool Offsets — The T Word
T0101 means tool 1, offset 1:
T 01 01
│ │
│ └── offset register (wear + geometry)
└── tool turret position (which station)
So T0202 = tool in turret position 2, using offset register 2. To cancel
the offset (when going to a safe position) call T0200 — same tool, no
offset.
7. Nose Radius Compensation (G41 / G42)
The control assumes the tool tip is a point, but in reality it has a small radius (typically 0.4 or 0.8 mm). For straight turns and faces this doesn't matter, but it ruins tapers and arcs. Comp tells the control "shift my path by the tool radius so the part is correct".
G42 G01 X20.0 Z0.0 F0.15 ; turn comp ON to the right (typical OD work)
X40.0 Z-30.0 ; cut taper — comp now active
Z-60.0 ; straight section
G40 G00 X100.0 Z50.0 ; ALWAYS cancel comp before retracting
Rules of comp:
- Engage in a straight
G01(or G00) move, NOT in an arc. - The lead-in move must be at least as long as the tool radius.
- Always cancel with
G40before tool change or program end.
8. The Big Five Canned Cycles — In Depth
G71 — Stock-Removal Roughing (Z-direction)
Probably the most-used cycle in turning. It takes a finished contour you define and removes everything outside it in parallel passes along Z.
G71 U2.0 R0.5 ; depth-of-cut = 2 mm, retract = 0.5 mm
G71 P10 Q20 U0.4 W0.1 F0.25
; │ │ │ │
; │ │ │ └── Z stock left for finishing (mm)
; │ │ └── X stock left for finishing (DIA, mm)
; │ └── last block of finishing contour
; └── first block of finishing contour
N10 G00 X20.0 ; ▼ finishing contour starts here
G01 Z0.0 F0.1
X25.0 Z-2.5 ; chamfer
Z-30.0
X40.0
Z-60.0
N20 X80.0 ; ▲ finishing contour ends here
What happens: the control reads the contour N10..N20, computes the
roughing passes (each 2 mm deep in X) parallel to Z, and removes stock
leaving 0.4 mm extra on diameters and 0.1 mm extra on Z faces for finishing.
G70 — Finishing Pass
After G71 you usually swap to a finishing tool and run:
T0303 ; finishing tool
G96 S220 M03
G00 X100.0 Z5.0
G70 P10 Q20 F0.08 ; runs the contour N10..N20 in one pass at F=0.08
G00 X150.0 Z150.0
G74 — Peck Drilling on Centreline
G00 X0.0 Z3.0 ; position drill on centre, 3 mm above face
G97 S1200 M03 ; constant RPM for drilling
G74 R1.0 ; retract distance between pecks
G74 Z-40.0 Q5000 F0.12 ; drill to Z-40, peck depth = 5.000 mm
Q is in microns on most Fanuc controls (5000 = 5.000 mm).
G75 — Grooving (X-direction)
Cuts a groove with peck retracts to break the chip:
G00 X42.0 Z-20.0 ; position above groove start
G75 R0.3 ; retract distance between pecks
G75 X28.0 Z-25.0 P2000 Q1500 F0.08
; │ │ │ │
; │ │ │ └── feed per rev
; │ │ └── Z step between adjacent grooves (microns)
; │ └── X peck depth (microns, 2.000 mm)
; └── final groove dia
G76 — Threading (multi-pass, fully automatic)
Modern Fanuc/Haas use the two-block form:
G00 X32.0 Z5.0
G97 S800 M03
G76 P020060 Q100 R0.05
; │ │ │ │ │
; │ │ │ │ └── finishing allowance on radius (mm)
; │ │ │ └── min depth of cut per pass (microns)
; │ │ └── thread tip angle (60°)
; │ └── chamfer at end (0 = none, 10 = 1 × pitch)
; └── number of finishing passes (02)
G76 X27.62 Z-30.0 R0 P1190 Q300 F2.0
; │ │ │ │ │ │
; │ │ │ │ │ └── PITCH (lead) of thread (mm/rev)
; │ │ │ │ └── first cut depth (microns, 0.300 mm)
; │ │ │ └── total thread depth (microns, 1.190 mm)
; │ │ └── taper amount (0 for parallel)
; │ └── thread end Z
; └── minor diameter (X target at full depth)
For an M30 × 2.0 thread on a 30 mm OD bar:
- Major Ø = 30, Minor Ø ≈ 30 − 2 × 0.6134 × 2 = 27.55 mm
- Total depth ≈ 0.6134 × pitch = 1.227 mm on radius
9. A Complete Worked Program
A part 80 mm long, finished diameters Ø50 → Ø40 → Ø30 with a 2 mm × 45° chamfer at the front and an M30 × 2.0 thread on the front 25 mm:
%
O0123 (TURNED SHAFT — DEMO)
(--- Tool 1: 80° rough, 0.8 mm nose R ---)
T0101
G21 G40 G99 ; metric, comp off, feed/rev
G50 S2500 ; rpm clamp
G96 S180 M03 ; CSS 180 m/min
M08 ; coolant on
G00 X82.0 Z2.0 ; safe approach
(--- Roughing G71 ---)
G71 U2.0 R0.5
G71 P100 Q200 U0.4 W0.1 F0.30
N100 G00 X26.0
G01 Z0.0 F0.10
X30.0 Z-2.0 ; 2 mm × 45° chamfer
Z-25.0 ; thread length
X40.0
Z-50.0
X50.0
Z-80.0
N200 X82.0
G00 X150.0 Z150.0
M09
M05
(--- Tool 3: finishing tool, 0.4 mm nose R ---)
T0303
G96 S220 M03
M08
G00 X82.0 Z2.0
G42 G70 P100 Q200 F0.08 ; finish pass with nose-R comp
G40 G00 X150.0 Z150.0
M09
M05
(--- Tool 5: threading tool ---)
T0505
G97 S800 M03
M08
G00 X32.0 Z5.0
G76 P020060 Q100 R0.05
G76 X27.55 Z-23.0 P1227 Q300 F2.0
G00 X150.0 Z150.0
M09
M05
(--- Tool 7: parting tool, 3 mm wide ---)
T0707
G97 S900 M03
M08
G00 X52.0 Z-83.0
G75 R0.3
G75 X-1.0 Z-83.0 P2000 Q0 F0.05
G00 X150.0 Z150.0
M09
M05
M30
%
Reading top-to-bottom: load rough tool → rough out the profile → swap to finisher → finish with nose-radius comp → swap to threading tool → cut the thread → swap to parting tool → cut off the part → end. That's a real turning program.
10. Quick Cheat Notes
- X is always diameter. Always.
- G96 for turning, G97 for drilling/threading.
- G42 is the normal direction of comp for OD turning, G41 for boring.
T0100at end of tool sequence cancels the offset before retract.- After
M30the program rewinds to the top automatically. - Pitch ≠ depth. Thread depth ≈ 0.6134 × pitch (60° metric thread on radius).
- Always retract to a safe XZ point before changing tools.
- Test new programs with single block (SBL) + rapid override at 25%.