---
title: "CNC lathe part program with G and M codes"
subject: "Manufacturing and Production Processes"
chapter: 9
key: "semester_4/manufacturing_and_production_processes:cnc-lathe-part-program-gcode"
source: https://www.bctengineer.com/q/semester_4/manufacturing_and_production_processes/cnc-lathe-part-program-gcode
site: BCT Engineering
---

# CNC lathe part program with G and M codes

Manufacturing and Production Processes · Chapter 9: Numerical Control of Machine Tools

- Asked in: year not given, 8 marks
- Video: [Introduction to part programming Using G & M Codes](https://www.youtube.com/watch?v=bTfeSFua-A8) — Engr. Asim Ahmad Riaz
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/manufacturing_and_production_processes/cnc-lathe-part-program-gcode
- Whole chapter: https://www.bctengineer.com/md/semester_4/manufacturing_and_production_processes/chapter-9

## Question

Explain the meaning of the following codes used in CNC programming: G00, G01, G02/G03, G28, G90/G91, M03, M05, M08, M30. Prepare a part program for a CNC lathe to machine a bar of 40 mm diameter and 100 mm length to the following shape: face the end; turn a 30 mm diameter for a length of 50 mm from the face with a 1.5 mm x 45 degree chamfer at the end of the 30 mm diameter. Use two roughing passes (diameter 40 to 36 mm, then 36 to 32 mm) and one finishing pass to 30 mm. Use diameter programming, 800 rpm and feed 0.2 mm/rev for roughing, and 1200 rpm and 0.08 mm/rev for finishing. The tool is T0101.

## Answer

#### Meaning of the codes

| Code | Meaning |
|---|---|
| G00 | Rapid positioning (no cutting) |
| G01 | Linear interpolation at programmed feed |
| G02 / G03 | Circular interpolation, clockwise / counter-clockwise |
| G28 | Return to the reference (home) position |
| G90 / G91 | Absolute / incremental dimensioning (on milling controls; lathes often use X, Z for absolute and U, W for incremental) |
| M03 | Spindle on, clockwise |
| M05 | Spindle stop |
| M08 | Coolant on |
| M30 | End of program and rewind |

G-codes are preparatory functions (motion and mode); M-codes are miscellaneous machine functions.

#### Assumptions

- FANUC-type format, metric units (G21), feed per revolution (G99), diameter programming (X is a diameter).
- Work zero (Z0) at the finished face; X0 on the axis. Stock Ø40.
- Roughing passes at Ø36 and Ø32 (2 mm depth per side each) leave 1 mm per side; the finish pass cuts to Ø30 and cleans the shoulder at Z-50.
- The chamfer is taken at the free (faced) end of the 30 mm diameter: Ø27 at Z0 rising to Ø30 at Z-1.5. The tool starts on the chamfer line 1 mm in front of the face (X25, Z1) so that it enters the cut smoothly.

#### Program

```text
O0100 (TURN DIA 30 X 50 WITH CHAMFER)
N10 G21 G99 G40 G97       (metric, mm/rev, cancel comp)
N20 T0101                 (select tool 1, offset 1)
N30 S800 M03              (spindle 800 rpm CW)
N40 G00 X42.0 Z2.0 M08    (approach, coolant on)
(FACING)
N50 G00 Z0.0
N60 G01 X-1.0 F0.1        (face to centre)
N70 G00 X42.0 Z2.0
(ROUGHING PASS 1 - DIA 36)
N80 G00 X36.0
N90 G01 Z-50.0 F0.2
N100 G00 X42.0 Z2.0
(ROUGHING PASS 2 - DIA 32)
N110 G00 X32.0
N120 G01 Z-50.0 F0.2
N130 G00 X42.0 Z2.0
(FINISH PASS WITH CHAMFER)
N140 G00 X25.0 Z1.0 S1200 (start on chamfer line)
N150 G01 X30.0 Z-1.5 F0.08 (1.5 x 45 deg chamfer)
N160 G01 Z-50.0           (finish dia 30)
N170 G01 X42.0            (clean shoulder face)
N180 G00 Z2.0
N190 G28 U0 W0 M05        (home, spindle stop)
N200 M09                  (coolant off)
N210 M30                  (end of program)
```

#### Notes on the program

- Each roughing pass retracts to X42, Z2 at rapid speed through the area already cut, so the tool does not drag over the work.
- The chamfer is a straight G01 move: the diameter changes by $2\times1.5 = 3$ mm (Ø27 to Ø30) over a length of 1.5 mm, giving 45 degree.
- Machining time of one roughing pass: $50/(0.2\times800) = 0.31$ min.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What do G00 and G01 do?
   A. G00 linear cutting; G01 rapid
   B. G00 clockwise arc; G01 counter-clockwise arc
   C. G00 rapid positioning; G01 linear interpolation at programmed feed
   D. Both cut at the same feed
   Answer: C. G00 is non-cutting rapid; G01 cuts at feed F. (Key point: G-codes)

2. Which M-code pairs are correct?
   A. M03 stop, M05 start, M08 coolant off, M30 pause
   B. M03 coolant on, M05 end
   C. M30 spindle stop, M08 spindle on
   D. M03 spindle clockwise, M05 spindle stop, M08 coolant on, M30 end and rewind
   Answer: D. M-codes are miscellaneous machine functions. (Key point: M-codes)

3. Why does the finish pass go to X27 at Z-50?
   A. A 1.5 x 45 deg chamfer reduces the diameter by 3 mm over 1.5 mm length
   B. The chamfer reduces diameter by 1.5 mm
   C. It leaves 1 mm per side stock
   D. It is a roughing allowance
   Answer: A. 30 - 2 x 1.5 = 27 mm; full diameter ends at Z-48.5. (Key point: Chamfer geometry)

4. Why does each roughing pass retract to X42 Z2 at rapid?
   A. To change the spindle speed
   B. So the tool does not drag over the cut surface
   C. To switch coolant on
   D. To face the end
   Answer: B. Rapid retract avoids marring the machined surface. (Key point: Roughing passes)

## Related in Manufacturing and Production Processes

- [Lathe operations, taper turning and turning calculations](https://www.bctengineer.com/question.md?key=semester_4%2Fmanufacturing_and_production_processes%3Alathe-operations-taper-turning-numerical) — Manufacturing and Production Processes, chapter 7
- [NC and CNC machines: elements and justification](https://www.bctengineer.com/question.md?key=semester_4%2Fmanufacturing_and_production_processes%3Anc-cnc-components-advantages-justification) — Manufacturing and Production Processes, chapter 9
- [Milling, shaper and drilling machine operations](https://www.bctengineer.com/question.md?key=semester_4%2Fmanufacturing_and_production_processes%3Amilling-shaper-drilling-machines-operations) — Manufacturing and Production Processes, chapter 7

## Related in other subjects

- [RA: employee-projects with no part used](https://www.bctengineer.com/question.md?key=semester_6%2Fdatabase_management_system%3Ara-emp-project-no-part) — Database Management System, chapter 3
- [Bullet embedded in bar, h = 260 mm](https://www.bctengineer.com/question.md?key=semester_3%2Fapplied_mechanics_dynamics%3Abullet-slender-bar-h260) — Applied Mechanics (Dynamics), chapter 6, asked 2×
- [Rate analysis: 40 mm PCC 1:2:4 floor](https://www.bctengineer.com/question.md?key=semester_7%2Festimating_and_costing%3Arate-pcc-1-2-4-floor-40mm) — Estimating and Costing, chapter 4
- [Rate analysis: 40 mm asphalt wearing coat](https://www.bctengineer.com/question.md?key=semester_7%2Festimating_and_costing%3Arate-asphalt-wearing-coat-10m2) — Estimating and Costing, chapter 4
