The first time you look at a CNC lathe program it is all G this and M that, and it reads like a cipher. Mine did too.

The good news is that the number of codes you genuinely use day to day is small. This article covers the ten G-codes to learn first and how to read a program, with a real example.

What G-code is, and how a program is put together

G-code tells the machine how to move. A lathe program is built out of these pieces.

AddressWhat it setsExample
GHow the machine moves (preparatory function)G01 = cut in a straight line
MMachine functionsM03 = spindle forward
TTool selectionT0101 = tool 1 with offset 1
SSpindle speed or surface speedS1500
FFeed rateF0.2 = 0.2 mm per rev
X / ZCoordinates (X across the diameter, Z along the axis)X50.0 Z-30.0
KEY POINT

On a lathe, X is normally programmed as a diameter. X50.0 means the tool sits at 25 mm on radius. Z is usually zeroed on the face, and goes negative as you move into the part.

The ten G-codes to learn first

CodeMeaningNotes
G00Rapid positioningFastest move, no cutting. Most crashes happen here, so watch the path it takes
G01Linear feedCuts in a straight line at the feed you set with F. The one you use most
G02Circular feed, clockwiseCut an arc, radius given with R
G03Circular feed, counter-clockwiseThe other direction
G28Return to referenceBack to machine home. Use it at a setup change or the end of an operation
G50Spindle speed clampThe safety limit when you are running constant surface speed
G96Constant surface speedHolds cutting speed in m/min as the diameter changes. Gives a consistent finish
G97Constant RPMUse this for threading and drilling
G41/G42Tool nose radius compensationCorrects nose radius error automatically. Full article here
G40Cancel nose radius compAlways cancel what you turned on with G41/G42

The M codes worth learning alongside

CodeMeaning
M03 / M04Spindle forward / reverse
M05Spindle stop
M08 / M09Coolant on / off
M30End of program, rewind to the top

Read a real one: an OD turning program

Take 50 mm bar down to 40 mm and put a step on it 25 mm long. A plain OD job. Follow it a line at a time.

O0001                  (program number)
G50 S2500              (clamp the spindle at 2500 rpm)
G96 S200 M03           (200 m/min constant surface speed, spindle forward)
T0101                  (call tool 1)
G00 X52.0 Z5.0 M08     (rapid up to the bar, coolant on)
G01 Z0 F0.25           (feed to the face)
X-1.6                  (face off, run just past centre)
G00 X46.0 Z2.0         (move to the start of the first cut)
G01 Z-25.0             (turn 46 dia for 25 mm)
X52.0                  (clear the part)
G00 Z2.0               (back to the start)
X42.0                  (second cut)
G01 Z-25.0             (turn 42 dia)
X52.0
G00 Z2.0
X40.0                  (finish size)
G01 Z-25.0             (finish 40 dia)
X52.0
G00 X150.0 Z100.0 M09  (back to the tool change position)
M30                    (end of program)

Written out like that, you can see it is the same four moves over and over. Go to the start, cut, clear, come back. G-code is not free composition, it is a set of stock phrases. Once you have the patterns, you can read it.

There is a shortcut: canned cycles like G71

In the example above every cut was written out by hand. On the shop floor you will more often see a canned cycle such as G71, the OD roughing cycle, where you write only the finished profile and let the control work out the roughing passes. G76 and G92 for threading are the same idea. It is worth understanding the moves with G01 first, then moving on to the cycles.

From writing G-code to reading it

If your reaction to all this was "that is a lot to remember", you are not wrong. The job is shifting, though. Writing G-code from scratch is becoming rarer, and reading, checking and occasionally correcting CAM output is becoming the normal way to work.

STRAIGHT TALK

Being able to read G-code will stay a valuable skill. The only person who spots the difference between the simulation and what the machine actually does is someone who can read the code. But keying it all in from scratch every time is not a thing you need to keep grinding at.

With LATHE-NC, the lathe CAM that runs in your browser, you load a DXF, check the simulation, and it outputs G-code like the program above. Being able to read what comes out is the point, and I hope this article helps with that.

Summary

Let the CAM do the typing.

LATHE-NC is three steps: load a DXF, check the simulation, output G-code.
The beta is free for the first 100 users.