A short milling program taken apart line by line: safety line, offsets, tool calls, cutting moves and program end.
A G-code program looks like noise until you read it one block at a time. Below is a short, generic milling program that cuts a square pocket outline. It is written to explain concepts, not to run. Dialects differ, so compare every line with your controller’s manual before using anything like it.
The program
O1001
G21 G90 G17
G54
T1 M06
S3000 M03
G00 X0 Y0
G43 H01 Z5.0
M08
G01 Z-2.0 F100
G01 X40.0 F300
G01 Y40.0
G01 X0
G01 Y0
G00 Z5.0
M09
M05
M30
Line by line
Program number
O1001 names the program in the controller’s memory. Some controls use a different prefix or none at all.
Safety line
G21 G90 G17 sets metric units, absolute positioning and the XY plane for arcs. Starting every program with a safety line means it won’t inherit leftover modes from the last job.
Work offset
G54 selects a stored work offset. It tells the machine where the part’s zero is, measured from machine zero. Without it, X0 Y0 means whatever was active last.
Tool and spindle
T1 M06 calls tool 1 and changes to it. S3000 M03 sets spindle speed and starts it turning clockwise.
Approach
G00 X0 Y0 rapids to the start corner. G43 H01 Z5.0 applies tool length compensation from offset 1 and moves to 5 mm above the part. Getting H and T to match matters. A mismatch is a classic cause of crashes. M08 turns coolant on.
Cutting
G01 Z-2.0 F100 feeds down 2 mm at a slow plunge rate. The next four G01 moves trace the square at 300 mm per minute. Because G01 is modal, only the first line needs it, but writing it each time makes the program easier to read.
Retract and end
G00 Z5.0 lifts clear. M09 stops coolant, M05 stops the spindle and M30 ends the program and rewinds.
Habits worth copying
- Start with a safety line
- Always state the work offset
- Retract before rapid moves across the part
- Comment generously if your control allows it
- Dry-run above the part before the first real cut
Next: G-codes versus M-codes, or look up any code in the CNC index.