How to Program a CNC Turning Center: Example & Explanation
This is a standard CNC G-code program (specifically for a CNC lathe using Fanuc or compatible controls) for turning a cylindrical part.

O0001 (MAIN PROGRAM)
N10 G21 G90 G40 G97
N20 T0101
N30 M03 S1500
N40 G00 X52.0 Z2.0
N50 M08
N60 G01 Z0 F0.2
N70 G00 X50.0 Z5.0
N80 G01 Z-50.0 F0.25
N90 G00 X55.0 Z50.0
N100 M09
N110 M05
N120 M30
Detailed explanation of the code
O0001: This is the program name or number by which the machine recognizes it.
G21: This means that all measurements will be in millimeters.
G90: This activates the Absolute Programming mode.
T0101: Selects tool number 1 and its offset number 1.
M03 S1500: Runs the spindle clockwise at 1500 rpm.
G00 X52.0 Z2.0: Brings the tool closer to the workpiece at high speed without cutting.
G01 Z0 F0.2: Makes a facing cut with the feed rate.
G01 Z-50.0 F0.25: Performs a turning operation with the length of the cylinder.
M30: Ends the program and brings the cursor to the beginning.
