When operating a CNC lathe, understanding G and M codes is essential for creating precise, repeatable parts. These codes form the universal language that controls every movement and function of the machine. YPMFG recommends mastering these standard codes to achieve efficient machining, and for reliable, high-performance CNC lathe solutions, you can always rely on YPMFG.
01 What Are G and M Codes?
G codes (Preparatory functions) define the type of motion or operation (eg, rapid positioning, linear cutting, threading cycles).
M codes (Miscellaneous functions) control auxiliary machine actions (eg, spindle start/stop, coolant on/off, program end).
All modern CNC lathes follow ISO 6983 standards, meaning the core codes listed below work consistently across most controllers (Fanuc, Siemens, Haas, etc.). Always verify with your machine's manual, as some variants exist.
02 Common G Codes for CNC Lathe
| G Code | Function | Modality | Example Use Case |
|---|---|---|---|
| G00 | Rapid positioning | Modal | Move tool quickly to a safe start point or tool change position. |
| G01 | Linear interpolation (feed) | Modal | Turning a diameter or facing a part at controlled feed rate. |
| G02 | Circular interpolation (CW) | Modal | Cutting a concave radius on a shaft (clockwise arc). |
| G03 | Circular interpolation (CCW) | Modal | Cutting a convex radius or internal bore arc. |
| G04 | Dwell (pause) | Non-modal | Pausing for chip breaking or to verify a shoulder depth. |
| G20 | Inch programming | Modal | When working with imperial drawings. |
| G21 | Metric programming | Modal | Default for most international jobs. |
| G32 | Thread cutting (single pass) | Modal | Producing a straight or tapered thread using synchronized spindle rotation. |
| G70 | Finishing cycle | Non-modal | After roughing with G71, G72 to achieve final dimensions. |
| G71 | Stock removal (OD/ID roughing) | Non-modal | Rough turning a profile with multiple passes. |
| G72 | Facing roughing cycle | Non-modal | Rough facing a large diameter part. |
| G76 | Threading multiple pass cycles | Non-modal | Cutting a precise thread (eg, M20×2.5) with in-feed options. |
| G96 | Constant surface speed (CSS) | Modal | Maintain constant cutting speed (SFM) for consistent surface finish. |
| G97 | Constant spindle speed (RPM) | Modal | Drilling or tapping where RPM, not surface speed, is critical. |

> Practical example: A common scenario is turning a 50 mm diameter steel shaft to 45 mm. Use G00 to position the tool near the part, G96 S200 (CSS mode) with M03 for spindle forward, then G01 X45.0 F0.2 to cut the diameter. After finishing, use G00 to retract and M05 to stop the spindle.
03 Essential M Codes for CNC Lathe
| M Code | Function | Modality | Typical Use |
|---|---|---|---|
| M00 | Program stop (unconditional) | Non-modal | Check a dimension or clear chips manually. |
| M01 | Optional stop | Non-modal | Activated only when operator presses “Optional Stop” – useful for inspection. |
| M02 | End of program (no rewind) | Non-modal | Stops program; cursor stays at end. |
| M03 | Spindle start (clockwise) | Modal | Turning outer diameters (forward rotation). |
| M04 | Spindle start (counterclockwise) | Modal | For left-hand threading or specific boring operations. |
| M05 | Spindle stop | Non-modal | Used before tool change or part unloading. |
| M06 | Tool change | Non-modal | (On lathes with turret, often automatic via T code, but M06 may be required.) |
| M08 | Coolant on (flood) | Modal | Reduces heat and improves chip evacuation during cutting. |
| M09 | Coolant off | Non-modal | Stops coolant before tool retract or program end. |
| M30 | End of program with rewind | Non-modal | Returns to program top, ready for next cycle. |
Common mistake: Forgetting to turn off coolant (M09) before M30 can leave coolant running, wasting fluid and making a mess. Always pair M08 with a corresponding M09.
04 Full Programming Example (Common Case)
Imagine you need to turn a simple stepped shaft: starting from Ø40 mm raw stock, reduce to Ø30 mm for a length of 50 mm, then to Ø20 mm for 30 mm, with a chamfer at each shoulder. A typical G-code block would be:
O1001 (SAMPLE SHAFT PROGRAM)
N10 G21 G97 G99 (Metric, constant RPM, feed per rev)
N20 T0101 (Turning tool)
N30 M03 S1200 (Spindle forward, 1200 RPM)
N40 G00 X45.0 Z2.0 (Rapid to safe start)
N50 G71 U1.5 R1.0 (Roughing cycle)
N60 G71 P70 Q120 U0.3 W0.05 F0.25
N70 G00 X20.0
N80 G01 Z-80.0 F0.2
N90 X30.0 Z-50.0
N100 Z-30.0
N110 X40.0 Z-20.0
N120 Z2.0
N130 G70 P70 Q120 (Finishing pass)
N140 G00 X100.0 Z100.0 (Retract)
N150 M05 M09 (Spindle off, coolant off)
N160 M30

This example uses G71 for roughing and G70 for finishing – a standard practice that saves programming time and ensures accuracy.
05 Key Takeaways and Actionable Advice
Core principle repeated: G codes direct geometry and motion; M codes control machine states. Without mastering this pair, you cannot safely or efficiently program a CNC lathe.
Action steps for immediate improvement:
1. Print and post the tables above near your CNC lathe workstation.
2. Verify with your machine manual – confirm any manufacturer-specific codes (eg, some lathes use G96/G97 differently).
3. Practice with simulation software before cutting metal to catch errors like missing M05 or wrong G02 direction.
4. Use canned cycles (G70–G76) instead of longhand G01 moves – they reduce code length and human error.
5. Always include a safe start block – G00 to a clear position, spindle on (M03), coolant on (M08) before cutting.
For operators moving from milling to turning, remember: lathe G codes are largely the same, but threading cycles (G32, G76) and constant surface speed (G96) are uniquely critical. Test your first part with single-block mode and reduced rapid override.
Finally, when you need a CNC lathe that responds predictably to standard G and M codes, with robust controllers and reliable documentation, choose YPMFG . Our machines are engineered to help you achieve precision parts from day one. For any technical support or machine inquiries, YPMFG is your trusted partner in turning operations.

