CNC Machine Tool Programming Example: Reading a Program Like a Machinist
This page walks through what a real cnc machine tool programming example looks like on the shop floor, which blocks of code carry the risk, and how to tell before the first cut whether a program will hold ±0.005 mm. Written for engineers and CAM programmers who have to release code, not just read it.

In this article
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
Key takeaways
What a CNC Machine Tool Programming Example Actually Contains
A cnc machine tool programming example is not a tutorial about G-codes in alphabetical order. It is a record of decisions. Every block answers one question: where does the tool go next, how fast, and with what compensation active. When we review a program before it runs on one of our 127 high-precision CNC machines, we read it in that order. Motion first. Then speed. Then offsets.
The first line that matters is the work offset. G54 through G59 tell the control where the part sits in machine space. Everything downstream inherits that decision. If the offset is set from a rough face that later gets machined away, the whole program shifts. We set offsets from a datum that survives every operation, usually a finished bore or a ground edge.
Next comes tool length. A program can be geometrically perfect and still scrap the part if T04 is called with the length offset of T03. On a 16-station mill-turn center this is easy to do, because the same turret holds turning tools and milling tools with very different lengths. We verify each H value against a physical measurement, not against the CAM library.
Only after offsets do we look at the cutting moves. That ordering surprises people. They expect the interesting part to be the contours. In practice, the contours are the easy part. The setup data underneath them is what decides whether the first part is good.
Arc Commands: CT and RND in Practice
Straight lines are unambiguous. Arcs are not. An arc needs a start point, an end point, a center or radius, and a direction. Get one of those wrong and the control either alarms out or, worse, cuts a smooth arc in the wrong place. That is why two specialized instructions, CT and RND, exist in many controllers.
CT completes the connection between a straight line and an arc, or between two tangent edges of a circle. You give it the geometry you know and the control solves the tangent point. No hand calculation, no rounding error, no gap where the line meets the arc. On a part with a dozen blended radii, that saves real programming hours.
RND handles inflection points. When an outline changes from convex to concave, the toolpath can leave a sharp corner that no cutter can actually produce. RND inserts an arc of a specified radius at that transition and connects it back to the adjacent lines or arcs. The result is a continuous path a ball nose or corner-radius tool can follow without chattering at the corner.
There is a limit. CT and RND assume the geometry is genuinely tangent. If your design intent is a hard corner with a 0.2 mm break, do not force an arc transition onto it. Let the sharp corner stand and control it with a smaller stepover instead. These commands solve tangency. They do not solve design intent.
Cutter Compensation and Why It Changes the Numbers
New programmers write toolpaths at the part surface. Experienced ones write them at the tool center and let G41 or G42 shift the path by the tool radius. That single choice changes how the program behaves when a cutter wears or when a regrind changes the diameter.
With compensation active, the operator can adjust the tool radius in the offset table and rerun. The geometry never changes. Without it, a 0.02 mm wear on a Ø10 mm end mill means editing every coordinate in the finishing pass, which is how mistakes get introduced at 11 pm.
The trade-off is that compensation needs room to engage. A lead-in move of at least half the tool diameter, usually 5–10 mm, gives the control space to ramp the offset in without gouging the wall. On internal corners tighter than the tool radius, compensation cannot help. You need a smaller tool or a different strategy.
We keep two versions of critical finishing programs: one with compensation for production, one without for the first article. The uncompensated version tells us the true machine and tool condition. The compensated version is what runs once the process is stable.
Feed, Speed, and the Numbers That Actually Hold Tolerance
A cnc machine tool programming example that ignores material behavior is a drawing exercise. Aluminum 6061 at 12 mm depth of cut and 8,000 rpm behaves nothing like 17-4PH stainless at the same settings. The program has to carry cutting data that matches the material on the job traveler.
For aluminum on a 3-axis machine, we typically run carbide end mills at 300–600 m/min surface speed with 0.05–0.15 mm feed per tooth. For 316L stainless, surface speed drops to 60–120 m/min, and feed per tooth to 0.03–0.08 mm. Titanium TC4 sits lower again. Inconel is its own category and rarely justifies a light finishing pass without a rigid setup.
Tolerance drives the strategy more than the material does. If a feature is called out at ±0.005 mm, roughing has to leave enough material that finishing removes a consistent load. We aim for 0.3–0.5 mm radial stock on finishing passes for tight features, and 0.05–0.1 mm for the final spring pass.
Surface finish follows the same logic. Ra 0.8–1.6 μm is achievable with a sharp tool and a stable setup at moderate feed. Pushing to Ra 0.2–0.8 μm usually means a dedicated finishing pass and a fresh insert, which is a scheduling decision as much as a programming one.
Verification Before the Spindle Turns
The cheapest crash is the one caught on the screen. We run three checks on every new program, and they take about fifteen minutes together. That is far less than a broken tool holder costs.
First, a graphical backplot with the stock model turned on. This catches gross errors: a tool going through a clamp, a rapid move at the wrong Z height, a missing clearance plane. Modern CAM does this automatically, but someone still has to look at it.
Second, a single-block dry run with the tool offset by 50 mm above the part, feed override at 10%. This confirms the machine reads the program the same way the CAM system does. Post-processor mismatches show up here and nowhere else.
Third, a first-article inspection. We measure the features that carry the tolerance callouts, not everything. For a typical bracket that means two bores, one face, and the overall length. If those are in, the rest usually follows. If one is out, we stop and find out why before running the second part.
Step by Step: From CAM Output to First Good Part
The sequence we follow on new jobs.
- 1Confirm the datumPick a surface that survives all operations. Set G54 from it and record the value.
- 2Verify tool length offsetsMeasure each tool physically. Never copy an H value from a previous job without checking.
- 3Backplot with stockRun the CAM simulation with fixtures and clamps modeled, not just the part.
- 4Dry run above the partOffset Z by 50 mm, single block, 10% feed override. Watch distance-to-go.
- 5Cut the first articleUse conservative feeds. Measure the tolerance features before running part two.
- 6Adjust and lockTune the compensation offset, then save the proven program as the production version.
When to Use Each Programming Approach
Match the approach to the geometry and the run size.
| Situation | Approach | Why |
|---|---|---|
| Tangent blends between lines and arcs | CT command | Control solves the tangent point |
| Outline with convex-to-concave inflection | RND command | Inserts a real arc at the corner |
| Tool wear varies during a run | G41/G42 compensation | Adjust radius in offset table, not code |
| Single prototype, tight tolerance | Uncompensated finish pass | Shows true machine and tool condition |
| Internal corner tighter than tool radius | Smaller tool or EDM | Compensation cannot reach into it |
| High-volume run, stable process | Compensated program | Reruns survive tool changes and regrinds |
| Deep cavity, long reach tool | Reduced feed and stepover | Deflection drives error, not the code |
Which Approach Fits Your Part
If the geometry is tangent and the run is repeatable, use CT and RND with cutter compensation and lock the program. If it is a one-off with tight callouts, skip compensation on the finish pass and check the machine first.
Questions Engineers Ask
Can CT and RND be used on any controller?
They are common on controllers that support conversational or high-level programming, and the exact syntax differs between brands. Check your control manual before writing them into a post-processor.
On controllers without them, you get the same result by calculating the tangent point in CAM and posting a standard G2 or G3 move with I, J, K or R.
Why does my program alarm on an arc that looks correct in CAM?
The most common cause is a mismatch between the arc center and the start or end point. The control checks that the radius from center to start equals the radius from center to end, usually within a small tolerance.
Rounding in the post-processor is the second cause. If coordinates are posted to three decimals, a long shallow arc can fail the check. Post four decimals for arc moves.
Should cutter compensation be in the control or in CAM?
For production runs, keep it in the control. You gain the ability to adjust for tool wear without reposting.
For first articles and one-off parts, posting the compensated path directly is simpler and removes one variable from the setup.
How much stock should finishing leave on a ±0.005 mm feature?
We aim for 0.3–0.5 mm radial stock on the semi-finish pass, then 0.05–0.1 mm on the final pass. That keeps the cutting load consistent without work-hardening the surface.
On stainless and titanium, leaving too little stock is worse than leaving too much. A rubbing pass dulls the tool and pushes the dimension out.
What is the fastest way to catch a wrong tool length offset?
Run the program in single block with the rapid plane set high, and watch the distance-to-go readout on the first Z approach. If the number looks wrong, stop before the tool reaches the part.
A graphical backplot will not catch this error, because the CAM model has the correct tool length. Only the machine knows the real one.
How do you handle a program that runs fine on one machine but not another?
Check the work offset and tool offsets first, then the control's default plane and units. G17/G18/G19 and G20/G21 differences cause more cross-machine problems than geometry does.
If the machines have different travel or spindle taper, the program may need a repost rather than an edit.
Send Us Your Program or Your Drawing
We review the toolpath, flag the risk points, and quote the job with a free DFM analysis inside 12 hours.
12-hour quote100% inspectionNo minimum order quantity