GreatLight CNC Machining Factory logo
CNC Machining
Rapid Prototyping
Materials
Industries
News
About GL

Get Instant Quote

Engineering explainer

CNC Program Basics: How G-Code Actually Drives a Machine

This page explains the CNC program basics behind every machined part: how a toolpath is built, what the controller reads, and where the real limits sit. It is written for design engineers and buyers who review drawings and quotes, not for full-time programmers. After reading it you can judge whether a program is sound, and when a part needs rework instead of a re-cut.

G-code & M-codeWork offsetsFeeds and speeds5-axis setups
FANUC CNC program basics reference for machining
Mental model

What a CNC program really is

A CNC program is a list of instructions that tells a machine where to move, how fast, and with which tool. Nothing more. The controller reads the list one block at a time, calculates the path, and drives the servos. What looks like magic on the shop floor is arithmetic running thousands of times per second.

Each block carries a few words. G words set the mode, such as G01 for a straight feed cut or G02 for an arc. X, Y and Z words give the endpoint. F sets feed rate, S sets spindle speed, T selects the tool. M words handle machine events like coolant on or spindle stop.

The order matters. A block that calls a tool before the previous tool retracts will alarm out. A block that changes feed before the tool enters the material will leave a mark. Programmers read this sequence the way an editor reads a sentence.

For the people who order parts, the useful takeaway is simple. If a feature cannot be reached by a moving tool along a controlled path, no amount of programming fixes it. Geometry decides first. Code follows.

  • 1
    G wordsSet motion mode or a canned cycle
  • 2
    Axis wordsGive the endpoint of the move
  • 3
    F and S wordsControl feed rate and spindle speed
  • 4
    M wordsTrigger machine events like coolant
Geometry

Where the program comes from: CAD, CAM, then code

Almost no one writes a full program by hand anymore. A designer builds a solid model in CAD. A programmer imports that model into CAM software, defines stock, fixtures and tools, then lets the software generate the toolpath. The CAM output is post-processed into the dialect the machine controller expects.

The post-processor is where quiet mistakes happen. A post written for a 3-axis mill will not handle a 5-axis simultaneous move correctly. If the post is wrong, the code looks fine on screen and cuts in the wrong place on the machine.

The programmer still edits the result. They shorten air moves, reorder tools to reduce changes, and adjust stepover to hit surface finish without wasting cycle time. This editing step is where a shop's skill shows up in the price.

At GreatLight we run 16 simultaneous 5-axis machining centers, 12 four-axis mills, 27 three-axis machines and 16 mill-turn centers across the shop. The post-processors, tool libraries and fixture standards are kept per machine, not shared loosely. That matters because a program built for a 750 × 1,150 × 550 mm envelope will behave differently on a 500 × 500 × 450 mm machine.

Coordinates

Axes, coordinates and why 5-axis changes the setup

A 3-axis machine moves in X, Y and Z. The part sits still. Everything is measured from a work zero that the operator sets with an edge finder or probe. Simple, fast, and fine for most prismatic parts.

A 5-axis machine adds two rotary axes. On a trunnion table the part tilts and rotates, so the tool can approach a face that would otherwise need a second setup. That is the real gain. Not speed. Fewer setups means fewer chances to lose datum.

Rotary motion also changes how coordinates work. The controller has to translate a move in part space into a combined linear and rotary motion. Small errors in the rotary center point show up as position error far from the table center.

This is why shops calibrate rotary centers and why a Ø400 mm rotary table needs care. A 0.01 mm error at the center becomes larger at the edge of the swing. On a 4,000 mm maximum processing size part, that lever effect is not small.

The rule of thumb for engineers: if a feature sits on five different faces and the tolerance is tight, 5-axis is usually the right call. If the part is a flat plate with holes on one face, 3-axis is faster and cheaper.

Cutting data

Feeds and speeds: the part of CNC program basics that decides tool life

Feed rate is how fast the tool moves through the material. Spindle speed is how fast it spins. The two are linked by chip load, which is the thickness of material each cutting edge removes per revolution.

Get chip load too low and the tool rubs instead of cuts. Heat builds, edges wear, and the finish goes cloudy. Get it too high and the tool chatters or snaps. The sweet spot depends on material, tool diameter, number of flutes and the rigidity of the setup.

Aluminium like 6061 or 7075 tolerates high spindle speeds and heavy feed. Stainless 316 and 17-4PH work-harden if the tool dwells, so the program keeps the cutter moving with a heavier chip. Titanium TC4 (Ti-6Al-4V) runs slower with more coolant and a shorter tool.

A programmer adjusts these numbers roughly: increase feed when the tool squeals, reduce it when the finish shows chatter marks. The controller stores them, but the judgment stays human. This is why a quote for the same part can differ between shops. The toolpath strategy is not the same.

Setup

Offsets, tool lengths and the errors that scrap parts

A program assumes the tool is exactly where the controller thinks it is. Work offsets tell the machine where the part zero sits. Tool length offsets tell it how long each tool is. Get either wrong and the cut lands in the wrong place.

Tool length is the more common failure. A tool measured once and reused without re-measuring after a change will drift. On a deep pocket, a 0.05 mm length error is enough to break through a floor that should have 0.2 mm of stock left.

Thermal growth also moves the machine. A spindle that has run for two hours is longer than a cold one. Shops that hold ±0.005 mm (±0.0002 in) often warm up the machine and re-check the first part before releasing the run.

In-process probing closes the loop. The machine measures a datum or a feature, feeds the result back into the offset, and cuts the rest of the batch from the corrected position. It costs cycle time. It saves rework on tight-tolerance parts.

Boundaries

When a sound program still cannot deliver the part

Programming cannot fix a design that the process cannot reach. A deep, narrow slot with a square internal corner needs a tool with a radius. If the drawing calls for a sharp internal corner, someone has to change the drawing or add EDM.

Thin walls are the second limit. A wall under about 0.8 mm will deflect under cutting force no matter how light the pass. The program can slow down, but the wall still moves. Sometimes the answer is a support fixture, sometimes a different process.

Surface finish has a ceiling set by the tool and the machine, not the code. As-machined surfaces run around Ra 1.6–3.2 μm. A high-finish pass reaches Ra 0.8–1.6 μm. Getting to Ra 0.2–0.8 μm usually needs a finishing operation beyond milling.

Tolerance is the last boundary. We hold ±0.005 mm (±0.0002 in) on parts that suit it, with 100% inspection before shipment. But a part with a 0.005 mm true position callout across a 500 mm span may need a different datum scheme before the first chip is cut.

Selection aid

Matching program strategy to the part

Use the left column to find the part type, then read the setup and the usual limit.

Part typeTypical setupMain limit
Flat plate, holes one face3-axis, one setupCycle time, not accuracy
Prismatic part, two faces3-axis plus soft jawsDatum shift between setups
Part with angled faces4-axis, rotary indexReach at the far end
Five-face complex part5-axis simultaneousRotary center calibration
Shaft with cross holesMill-turn centerTool clearance, bar pull
Deep pocket, tight floor3-axis plus probingTool length drift
Thin wall under 0.8 mmAny, with supportDeflection, not code

The short version

If a feature sits on one or two faces and the tolerance is normal, a 3-axis program is faster and cheaper. If the part has tight true position on five faces, choose 5-axis and accept the higher setup cost, because one good setup beats three risky ones.

FAQs

Questions engineers ask about CNC program basics

Do I need to supply a CAD model or can you work from a drawing?

A 3D model is faster and removes ambiguity. A 2D drawing with clear dimensions works too, but someone has to rebuild the geometry, and that step can introduce errors.

If you send a STEP file plus a drawing with tolerances and finish callouts, we can quote and start without back-and-forth.

How do you decide between 3-axis and 5-axis for my part?

We look at how many faces carry features and how tight the position tolerance is. Features on one or two faces usually go on a 3-axis machine.

When a part needs four or five faces and the true position is tight, 5-axis pays for itself by removing setups. A second setup can add more error than the rotary motion costs.

Can a program be reused for a repeat order?

Yes, and we keep it with the fixture record. On a repeat order the program and offsets are recalled, and the first part is checked before the run continues.

If the material or the tooling changes, the cutting data is re-tuned. The geometry stays the same.

What surface finish can a program realistically deliver?

As-machined surfaces land around Ra 1.6–3.2 μm. A high-finish pass gets to Ra 0.8–1.6 μm. Below that usually means a separate finishing operation.

The tool radius, stepover and machine rigidity set the floor. Code alone cannot push past it.

How do you protect my design files?

Uploads are secure and confidential, and we sign an NDA on request. Files are shared only with the people who program and machine the part.

We hold ISO 27001:2022 for information security, alongside ISO 9001:2015, IATF 16949:2016 and ISO 13485:2016 for quality.

What happens if the first part is out of tolerance?

The machine is stopped and the offset is corrected before the run continues. With in-process probing, the correction is fed back automatically.

Every part is inspected before shipment, and inspection reports are available on request.

Send a drawing and get a program-ready quote

Share your model or drawing and we come back with a quotation and a free DFM analysis within 12 hours. No minimum order quantity, from one prototype to 10,000+ part runs.

12-hour quote100% inspectionNo minimum order

Follow

More from the shop

We publish setup notes, tooling trials and inspection data from the factory floor.

FacebookTikTokYouTubeLinkedInInstagramThreadsPinterest

Trusted by engineers and manufacturers worldwide

Tesla Ford Motor Company BYD Auto Denso Magna International Boeing Airbus Medtronic KUKA FANUC