How to write G-code to face a 2.5" Ø part on a CNC lathe
Complete paste-able program for facing 0.030" off a 2.5" diameter bar in 4140 prehard, plus the math behind G50/G96, feed/speed, and the safe-retract sequence that keeps the insert away from the chuck.
Facing a 2.5" diameter part on a CNC lathe is the "hello world" of turning programs. The math is short, the G-code is six active lines, and getting it wrong is how new operators crash an insert into the chuck. Below is a complete, paste-able program for facing a 2.5" OD bar in 4140 prehard, plus the math behind every line so you can change diameters or materials without copying something off a forum.
The setup we're programming
- Workpiece — 2.5" Ø round bar, 4140 prehard (~30 HRC), held in a 3-jaw chuck with ~3" of stickout.
- Stock to face off — 0.030" (typical for second-op facing after sawing).
- Tool — T0101, OD turning insert, 80° diamond (CNMG432-MM, AlTiN coated).
- Coolant — flood, on through the run.
- Z-zero — the finished face (so "face the part" means cutting until Z = 0).
- X-zero — the spindle centerline (X0 = center of bar).
The math: pick the SFM and the feed
Material: 4140 prehard (~30 HRC)
Carbide insert SFM range: 220–300 (turning)
Pick: SFM = 280
Maximum RPM at the largest diameter (2.5"):
RPM = (SFM × 12) / (π × D)
= (280 × 12) / (π × 2.5)
= 3360 / 7.854
= 428 RPM
As the tool feeds toward center, D decreases. With G96 (constant SFM),
the lathe will spin faster to maintain SFM. Cap with G50 to protect
the spindle and the chuck.
G50 spindle cap = 2,500 RPM (typical for 8" 3-jaw chuck)
↑ this is the safety stop on near-center facing.Feed and depth-of-cut
Roughing pass (one shot, removing 0.030"): Feed: 0.012 in/rev DOC: 0.030" (single Z-step) Finish pass (after the rougher, springing back to Z = 0): Feed: 0.006 in/rev DOC: 0.005" wipe pass For most 0.030" face stock you can rough + finish in one Z-step of 0.030" at 0.008 IPR. Adjust if surface finish is critical.
The complete G-code program
% O0001 (FACE 2.5 OD x 0.030 STOCK 4140 PREHARD) (SETUP) G20 G18 G40 G80 (INCH, ZX PLANE, CANCEL COMP/CYCLES) G28 U0 W0 (HOME TURRET, SAFE START) (TOOL CALL — OD ROUGHER) T0101 (T01 = STATION, .01 = OFFSET) M8 (COOLANT ON) (SPINDLE — CONSTANT SFM @ 280) G50 S2500 (CAP RPM AT 2500) G96 S280 M3 (CSS 280 SFM, FORWARD) (APPROACH) G0 X2.7 Z0.05 (RAPID ABOVE BAR, 0.05 OFF FACE) (FACE PASS — FEED FROM OD TO BEYOND CENTER) G1 X-0.030 F0.012 (FACE OFF 0.030 OF STOCK) (RETRACT) G0 Z0.5 (BACK OFF Z FAST) G0 X3.0 (RAPID OFF DIAMETER) (SPINDLE OFF, BACK TO RPM MODE) G97 S400 M5 (CANCEL CSS, STOP SPINDLE) M9 (COOLANT OFF) G28 U0 W0 (HOME) M30 %
Line-by-line, why each one is there
%— program-start sentinel, Fanuc/Haas convention.O0001— program number. Pick something you'll remember.G20 G18 G40 G80— defensive: inch units, ZX plane (turning), no cutter comp, no canned cycle. Always set these in case the previous program left modal codes weird.G28 U0 W0— home in machine coords. Safest place to start a tool change.T0101— tool 1, offset 1. Different machines disagree on the offset format; this is universal.G50 S2500— cap RPM at 2,500. Critical before G96.G96 S280— constant surface speed at 280 SFM. Lathe now adjusts RPM to keep cutting speed constant as diameter changes.G0 X2.7 Z0.05— rapid to 0.1" above the OD and 0.05" off the face. The "0.2" over diameter" is your safe-approach margin.G1 X-0.030 F0.012— this is the cut. Feeds the tool from X = 2.7 down to X = -0.030 at 0.012 IPR. Negative X means past center — ensures a clean face with no nub.G0 Z0.5— retract Z fast. Always retract Z before X to avoid scraping the face.G97 S400 M5— cancel constant SFM (back to RPM mode), spindle stop.M30— program end with rewind.
Gotchas that scrap the part (or the spindle)
Adapting to other diameters and materials
Same program, different bar: Bar OD 1.0": Approach X1.2, RPM cap can stay at 2500. Bar OD 5.0": Approach X5.2, drop SFM to 250 (chuck balance). Bar OD 8.0": Approach X8.2, drop SFM to 220, cap RPM at 1500. Different material (keep tool, keep DOC): 6061 aluminum: SFM 1000, IPR 0.015 (single pass at 0.030) 1018 mild steel: SFM 350, IPR 0.012 304 stainless: SFM 180, IPR 0.008 (don't dwell, work-hardens) 4140 hardened: SFM 120, IPR 0.005 (light passes only)
Run it on your phone
The ShopCalc app holds the SFM ranges for every common material, generates the RPM and feed for a given diameter, and includes a G-code generator for facing, threading, drilling, and simple OD/ID turning — including the G50/G96 sequence above. Plug in the diameter, pick the material, get a ready-to-run program. 100% offline. Free on the App Store and Google Play.
Related
- Speeds and feeds for 1/4" 4-flute carbide in 4140 steel
- Tap drill chart for 1/2-13 UNC at 75% thread
- Speeds and feeds — the full reference
- ShopCalc — machinist calculator on iOS + Android
Note: Always dry-run a new program with the spindle off and the door closed. Verify the toolpath in single-block before the first real cut.
