Home › CNC Path › What a CNC program is
Step 4 of 8 · 8 min

What a CNC program is

A CNC program is a text file. Nothing more. A list of lines the machine reads from top to bottom, one after another, and executes exactly as written. There is no intelligence and no interpretation: if the line says come down 30 millimetres, it comes down 30 millimetres, whether there is a part underneath or a vice.

Grasping that — that it is a list of literal orders in order — is 80% of losing your fear of it.

What a line looks like inside

Every line, called a block in the trade, is made of letters followed by numbers. Each letter means one thing:

N40 G01 X50. Y25. F250 S1200 M08

The N numbers the block and is optional: it lets you refer to it ("stop me at N40"). The G says how to move. X, Y, Z are the destination coordinates. F is the feed, the speed at which it travels while cutting. S is the spindle speed. And M switches something on or off — here, the coolant.

Not every letter has to appear on every line. If one is missing, the machine keeps the last value you gave it. That is what being modal means, and it is convenient and dangerous in equal measure: a feed or a plane you drag along without noticing from twenty lines earlier.

G and M: the two families

The G codes are preparatory functions: they describe the movement. Move fast, move cutting in a straight line, describe an arc, work in millimetres, measure from the work offset.

The M codes are auxiliary functions: they operate the machine. Start the spindle, stop it, open the coolant, change the tool, end the program.

A rule of thumb: if the order moves something, it is a G; if it switches or actuates something, it is an M.

Where the program comes from

There are two routes, and in a real shop both live side by side.

Written by hand, straight into the control or in a text editor. That is normal for simple parts, touch-ups, facing, a hole, a slot. A machinist who knows the trade writes thirty lines in five minutes.

Generated by CAM, from the 3D model. The programmer defines the operations — roughing, finishing, drilling — and the software writes the thousands of lines needed. Nobody hand-writes the finishing pass of a mould.

Between the CAM and the machine there is a piece worth knowing about: the post-processor. It is what translates the CAM's generic output into the specific dialect of your control. A program post-processed for a Haas will not run as-is on a Fanuc.

Who loads it, and what happens before cycle start

The program reaches the control over the network, on a USB stick, or typed in right there. But between loading it and pressing the green button there are four things a person does, and that no program solves:

Clamp the part, so it takes the cutting forces without moving.

Put the tools in the magazine, in the numbers the program expects. If the program calls T03 and there is something else in T03, the machine picks it up anyway.

Measure and load the offsets: each tool's length and its radius. Without this the machine does not know where the tip is.

Set the work offset and store it in G54. It is the origin everything in the program is measured from.

All four belong to the operator, not to the program. And all four are where the expensive mistakes cluster.

The first time, you always simulate

No new program goes straight to cutting. The usual order:

First graphical simulation on the control or in the CAM, which shows the toolpath and warns about obvious collisions. Then a dry run, with the machine executing the program with no part, or with the Z axis shifted upwards, so you can watch the real movements. Then the first part at reduced feed, with a hand on the feed override and a finger over the stop button. And only then, production.

Skipping that is what produces the stories they tell in workshops.

What a program does not do

Worth saying plainly, because it marks where the CNC ends and the trade begins. The program does not know whether the tool is sharp. It does not know whether the part is properly clamped. It does not know whether the material is what you think it is. It does not decide speeds and feeds: it executes them, and you or the CAM decide them. And it does not tell air from steel: if you tell it to go in at 500 mm/min, in it goes.

That is why an operator with judgement is worth more than a perfect program. The program is the score; the one playing is still the person standing at the machine.


Next step: you now know what a program is and how a line is put together. Next comes recognising the instructions that appear in almost all of them: the ten codes you will see in any program in the shop.