How to Make CNC Machine Program
A working procedure for turning a 3D model into G-code that holds tolerance on the first run. Written for design engineers and CAM programmers who need to know which parameters matter, where programs fail, and when manual code still beats CAM.

In this article
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
Key takeaways
Define part requirements and DFM constraints
Every program starts as a set of decisions, not as a line of code. Before opening CAM, list the functional surfaces, the datum scheme, and the tolerances that actually matter. A bearing bore at ±0.005 mm and a clearance hole at ±0.2 mm should never get the same finishing strategy. Write the critical dimensions down and mark them on the drawing.
Then check the part for features that fight the cutting tool. Deep pockets narrower than 4× the tool diameter, sharp internal corners, and threads that stop against a shoulder all drive cost. Adding a fillet slightly larger than the tool corner radius lets you use a bigger, stiffer cutter. It is a five-minute model change and often removes a second operation.
Material sets the cutting parameters. Aluminum 6061 and 7075 run fast with high rake angles; 316L stainless work-hardens if you dwell, so keep the feed per tooth up and never let the tool rub. Titanium Ti-6Al-4V and Inconel need lower surface speed and more coolant pressure. Choose the insert grade and coating after the material, not before.
- 1Datum strategyPick datums that exist on the raw stock so the first setup can be probed.
- 2Tolerance mapSeparate critical dimensions from cosmetic ones on the setup sheet.
- 3Wall thicknessBelow 0.8 mm in aluminum, plan a finishing pass with light radial engagement.
- 4Thread depthKeep at least 2× pitch of full thread for reliable gauging.
Choose manual programming or CAM software
Manual G-code is still the right answer for simple 2.5D work: face milling, drilling patterns, a single counterbore, or a quick fixture plate. You can write it at the machine, edit it in seconds, and there is no post-processor to debug. For a part with six holes and two pockets, CAM setup time often exceeds the time saved.
CAM takes over as soon as you have 3D surfaces, blended fillets, or more than one setup. Modern CAM handles rest material, tool holder collision, and adaptive clearing that keeps radial engagement constant. On a 5-axis part with undercuts, hand-writing code is not realistic. The trade is setup time versus cutting time: complex parts usually justify the CAM session.
A middle path works well for shops that run the same families repeatedly. Build a template with stock setup, WCS, tool library, and feeds already loaded. The programmer then only picks geometry and adjusts the stepover. Templates cut programming time and, more importantly, stop parameters from drifting between operators.
- 1Manual is fine forFacing, spot drilling, bolt circles, simple slots, fixture plates.
- 2CAM is required for3D contoured surfaces, rest machining, 5-axis simultaneous, complex fixturing.
- 3Hybrid approachCAM for the geometry, hand edits for entry points and retract moves.
Prepare the CAD model for machining
Import the model, then delete what the machine does not need. Suppressed features, cosmetic logos, and internal threads modeled at nominal size all create noise. If the part is a weldment or an assembly, collapse it to a single solid. Any gap or sliver face will produce a broken toolpath that looks fine in preview and fails at the machine.
Define the stock next. A 100 × 100 × 20 mm aluminum block for a small enclosure leaves enough material for clamping and for a 1-2 mm facing cut on each side. Add stock deliberately: 2 mm on machined faces, 5 mm on saw-cut faces, and more where the part will be held in a vise. Undersized stock is the most common reason a program has to be rewritten.
Set the work coordinate system at a feature you can touch off or probe. A corner of the stock, the center of a bored hole, or a dedicated fixture boss all work. Avoid using a theoretical intersection that only exists in the model. If the operator cannot find the WCS with an edge finder or a probe, the program will run offset.
- 1Heal the geometryRun a model check for gaps, overlapping faces, and zero-thickness walls.
- 2Stock plus2 mm on finished faces, 5 mm on saw cuts, more where clamping is needed.
- 3WCS placementUse a probeable corner or bore, never a theoretical point.
Generate toolpaths and set cutting parameters
Roughing first. Adaptive or trochoidal clearing holds radial engagement around 10-15% of tool diameter and axial depth up to 2-3× diameter in aluminum. That combination removes material fast without burying the cutter. On stainless and titanium, drop axial depth to 1× diameter and keep the feed per tooth at 0.05-0.1 mm so the edge cuts instead of rubs.
Finishing decides surface finish. A stepover of 5-10% of tool diameter gives a scallop height in the Ra 0.8-1.6 μm range on most aluminum parts. Push stepover to 20% and you will see witness lines under light. If the drawing calls for Ra 0.2-0.8 μm, plan a separate finish pass with a smaller stepover or a different tool, and expect the cycle time to rise.
Order the operations so the part stays rigid. Rough both sides, then finish the faces that locate the second setup, then finish everything else. Drill before you ream, ream before you bore. Cut the outside profile last when the part is thin, and leave tabs or a sacrificial web so the part does not move when the contour releases it.
- 1Roughing stepover10-15% of tool diameter with adaptive clearing, 60-70% for conventional.
- 2Finishing stepover5-10% of tool diameter for Ra 0.8-1.6 μm; less for finer finishes.
- 3Operation orderRough, locate, finish critical faces, then profile and release.
- 4Thin wallsLeave tabs or a web; a released 0.8 mm wall will spring.
Simulate, post-process, and prove out the code
Simulation must include the holder, the chuck or vise, and the fixture. Most crashes are not the tool hitting the part, they are the holder hitting a clamp during a rapid move. Check every rapid at full speed in the simulation, then check the retract plane between operations. A clearance plane 5 mm above the stock is safer than 1 mm and costs almost nothing.
Post-processing converts the internal toolpath into machine-specific G-code. The post must know the control model, the axis configuration, and whether the machine uses G54 or a pallet offset. A generic post will produce code that runs but may reverse an axis or output the wrong arc format. Test a new post on a scrap block before it touches a production part.
Prove out in three stages. First, run the program with the tool offset 5-10 mm above the stock and watch the position display. Second, cut the first part with feed override at 50% and single block on. Third, measure the critical dimensions and adjust cutter compensation or wear offsets from the inspection report, not from feel. Record the offset change so the next run starts from a known state.
- 1Simulate fixturesHolder and clamp collisions are the most common crash cause.
- 2Clearance plane5 mm above stock for rapids; more if the fixture is tall.
- 3Post validationCut a scrap block first when a post or machine is new.
- 4Offset disciplineAdjust wear offsets from measured data and log the change.
Seven steps from model to proven G-code
Follow in order. Skipping a step usually shows up as a scrapped first part, not as a warning in CAM.
- 1Freeze the drawing and datum planMark critical dimensions, datums, and tolerances. Note material and heat treatment. A drawing change after programming invalidates the setup sheet.
- 2Run a DFM checkLook for deep narrow pockets, sharp internal corners, and threads against shoulders. Add corner fillets slightly larger than the tool radius and confirm wall thickness above 0.8 mm in aluminum.
- 3Clean the CAD modelDelete cosmetic and suppressed features, stitch surfaces, and confirm a single watertight solid. Repair gaps before importing into CAM.
- 4Define stock, WCS, and fixturesAdd 2 mm on finished faces and 5 mm on saw cuts. Place the WCS on a probeable corner or bore. Model the vise jaws and clamps in the setup.
- 5Build roughing and finishing toolpathsAdaptive roughing at 10-15% radial engagement, axial depth 2-3× diameter in aluminum. Finish at 5-10% stepover for Ra 0.8-1.6 μm. Order operations to keep the part rigid.
- 6Simulate with holders and fixturesRun the full program at speed, check every rapid and the clearance plane. Re-run after any parameter change, not only after geometry changes.
- 7Post, dry run, and cut the first articlePost with the correct machine configuration. Dry run 5-10 mm above stock, then cut at 50% feed override in single block. Measure and log offset changes.
Manual programming vs CAM by part type
Use this to decide where to spend programming hours.
| Part situation | Manual G-code | CAM software | Main risk |
|---|---|---|---|
| Face milling and simple slots | Preferred | Works but slower to set up | Typo in coordinates |
| Drilling patterns, bolt circles | Preferred | Overkill | Wrong tool length offset |
| 2.5D pockets with islands | Possible | Preferred | Leftover material in corners |
| 3D contoured surfaces | Not practical | Required | Scallop height out of spec |
| 5-axis simultaneous cuts | Not practical | Required | Holder collision |
| Repeat family, same tooling | Template plus edits | Template preferred | Parameters drifting between runs |
| One-off fixture plate | Preferred | Waste of setup time | Clamp interference |
When to program in-house and when to send the file out
If you have the CAM seats, the post-processors, and operators who run the same machine family every day, program in-house. If the part is 5-axis, tight-tolerance, or the first article is due this week, send the model to a shop that already has the posts and the inspection loop in place.
Common questions
Can I write a CNC program without CAM software?
Yes, for 2.5D work. Facing, drilling, tapping, and simple pockets can be written by hand with G54, G81, and G41/G42. You need to calculate coordinates and feeds yourself.
Once the part has 3D surfaces, blended fillets, or undercuts, hand-written code becomes error-prone. The time saved on software is usually lost in dry runs and scrapped first parts.
What stepover gives Ra 0.8-1.6 μm?
On a typical 10 mm ball or bull nose tool, a stepover of 5-10% of the tool diameter keeps scallop height in that range on aluminum. Larger tools tolerate a larger stepover for the same scallop height.
If the drawing specifies Ra 0.2-0.8 μm, reduce stepover further or plan a separate finish pass. Check the result with a profilometer rather than judging by eye.
Why does the program run correctly but the part is out of tolerance?
Check the work coordinate system first. A WCS set on a saw-cut face with 0.5 mm of variation shifts every feature on that side.
Then check tool wear offsets and cutter runout. Thermal growth over a long cycle also moves dimensions; measure a warm part, not one straight off the machine.
How do I verify a new post-processor?
Post a known part and compare the output against the machine's accepted code format. Check arc output (G02/G03 with I/J or R), tool change sequence, and axis directions.
Run the code on a scrap block with the tool 5-10 mm above the stock before it goes anywhere near a production part.
Does the program need to change for different materials?
Yes. Surface speed, feed per tooth, and axial depth all change. Aluminum 6061 runs at high surface speed with deep axial cuts. 316L stainless and Ti-6Al-4V need lower surface speed, higher feed per tooth, and enough coolant to prevent work hardening.
Keep a material-specific tool library so the parameters follow the material instead of the operator.
How many setups should a part have?
As few as the geometry allows. Each setup adds a locating error and a chance for chips to sit under the part. Five-axis machines can often finish a part in one or two setups that would take four on a 3-axis machine.
When a second setup is unavoidable, machine the locating features in the first setup so the second one repeats.
Send us the model and get a programming review
We return a quotation and a free DFM analysis within 12 hours, including notes on features that will drive cycle time or force an extra setup.
12-hour quoteFree DFM analysis±0.005 mm capabilityNDA on request