How to CNC Machine Program
This guide walks through the full programming workflow for a 3-axis or 5-axis mill: from reading the drawing to the proven first cut. It is written for machinists, process engineers, and buyers who need to judge whether a program is ready before metal is cut. After reading, you will know which steps cannot be skipped and which parameters to check first.

In this article
- 1
- 2
- 3
- 4
- 5
- 6
- 7
What matters most
Read the drawing before you write code
Programming starts at the drawing, not at the keyboard. Identify the datum faces, the tightest tolerance, and the surface finish callout. On a typical aluminum bracket, the ±0.005 mm tolerance usually sits on one bore or one mating face, and the rest of the part is open to ±0.1 mm. That difference decides how many setups you need.
Check for features a 3-axis machine cannot reach. An undercut, a cross-hole, or a face that needs two directions of access usually means a 4-axis or 5-axis setup. If the part has such features on three sides, plan for a 5-axis machining center rather than three separate fixtures. Fewer setups means fewer datum shifts and less stack-up error.
Note the material too. Aluminum 6061 cuts at 3,000–6,000 rpm on a 12 mm end mill, while 17-4PH stainless needs roughly one-third of that speed with a carbide tool and constant coolant. The material grade changes the whole feed and speed table before programming begins.
- 1Datum firstPick the face that locates in the fixture as your program zero.
- 2Tolerance mapList every dimension under ±0.05 mm and inspect those features in-process.
- 3Access checkFlag any feature that needs tool access from more than one direction.
Choose the programming method and the CAM setup
Manual G-code is fine for simple profiles, drilled holes, and one-off repair work. CAM software is the practical choice once a part has more than about twenty toolpath segments, curved surfaces, or multiple setups. Most shops use CAM and then hand-edit the output for safety blocks and tool-change positions.
Inside CAM, define the stock from the actual bar or plate size, not from a rounded guess. Set the work coordinate system to the datum you chose on the drawing. Then build the tool list: rough with a large end mill, semi-finish with a smaller one, and finish with a tool that matches the smallest internal radius. A 6 mm corner radius cannot be cut by a 12 mm cutter.
Choose the post-processor that matches the machine control. Fanuc, Siemens, and Heidenhain handle canned cycles and high-speed look-ahead differently. A program that runs clean on one control can alarm out on another because of G-code dialect, arc formatting, or tool-change syntax.
- 1Small radius ruleThe finishing tool diameter must be smaller than twice the smallest internal radius.
- 2Post-processor matchConfirm the post against the actual control before the first run.
- 3Stock accuracyModel the real stock; an oversized blank changes the first roughing pass.
Set feeds, speeds, and the tool list
Feeds and speeds come from chip load. For a 12 mm carbide end mill in 6061 aluminum, a starting chip load of 0.05–0.10 mm per tooth at 4,000–6,000 rpm gives a stable cut with air blast or flood coolant. Use the lower end for slotting and the higher end for light side milling. In 304 stainless, drop the surface speed to around 80–120 m/min and use flood coolant without exception.
Depth of cut matters as much as speed. In aluminum, a radial engagement of 40–50 percent of the cutter diameter with an axial depth of one to two times the diameter works well with a rigid setup. In stainless or tool steel, keep axial depth at 0.5–1 times the diameter and reduce radial engagement to 20–30 percent. Push harder and the tool will chatter or break.
Group tools so the machine changes as few times as possible. A typical sequence is face mill, large rougher, small rougher, drill, tap, finish end mill, chamfer tool. Tapping needs a synchronized feed, so verify the pitch and the spindle direction before the cycle starts. A rigid tapping cycle at 1,000 rpm with a 1.25 mm pitch needs a feed of 1,250 mm/min exactly.
- 1Chip load over rpmSet feed per tooth first, then calculate the spindle speed.
- 2Coolant by materialAluminum tolerates air blast; stainless, titanium, and tool steel need flood.
- 3Tap syncMatch feed to pitch exactly or the thread will strip.
Prove the program before the production run
A program is not proven until the first part measures in tolerance and the cycle is repeatable. Keep the first article and record the actual offsets you used. If the machine has a probe, program the probe to check the tight-tolerance bore or face, and write the result into a report. For ±0.005 mm features, in-process probing is more reliable than trusting a single touch-off at the start of the run.
Watch the cycle time and the tool load together. If the load meter sits near the spindle limit during roughing, reduce the radial engagement rather than the feed, because feed reduction just rubs the tool and shortens life. If a finishing pass leaves chatter marks, check the tool overhang first. Reducing overhang by 20 mm often does more than changing speed.
Document the revision. When a program is edited at the machine, the office copy and the shop copy drift apart within weeks. Write the change on the setup sheet, mark the revision number at the top of the program, and keep the proven file in a controlled folder so the next run starts from a known state.
- 1First articleMeasure the tight features and record the offsets that produced them.
- 2Load meterKeep roughing under about 70 percent of the spindle load rating.
- 3Revision controlOne proven file, one revision number, one folder.
How to CNC machine program: 7 steps to a proven first cut
- 11. Write the setup sheetList the operation number, workholding, datum, stock size, and the tools for each setup. Include the zero point in X, Y, and Z. A setup sheet on the bench prevents half the errors that happen at the control.
- 22. Build the CAM operations in orderFace, rough, semi-finish, drill, tap, finish, chamfer. Keep roughing and finishing in separate operations so you can adjust one without disturbing the other. Set stock-to-leave at 0.2–0.3 mm for the finishing pass.
- 33. Simulate the full programRun the CAM simulation with the actual holder geometry and stock model. Check for holder collisions, rapid moves through the part, and tools that cut air for most of the cycle. Fix the order before you post the code.
- 44. Post and hand-check the G-codeRead the first 30 and last 20 lines. Confirm the work offset (G54–G59), tool length compensation (G43 H), and the cancel blocks (G40, G49, G80, M09, M05). Remove any rapid move that passes below the top of the stock.
- 55. Set tools and offsets on the machineMeasure every tool length on the presetter or with a touch-off. Enter the work offset from the datum corner. Then verify by moving to the XY zero and the Z zero above the part with single block active.
- 66. Dry run and single blockRun the program with rapid override at 25% and feed hold ready. Watch the distance-to-go screen, not just the part. On the first cutting pass, reduce feed override to 50% until the cutter is fully engaged and the sound is steady.
- 77. Inspect the first part and lock the programMeasure the tight-tolerance features at the machine with a micrometer or bore gauge. Adjust wear offsets by the measured difference, cut the second part, and confirm. Then save the proven program and offsets together as a controlled revision.
Starting parameters and where each method fits
Use these as first-cut ranges, then adjust to the setup rigidity and tool grade.
| Work | Method | Starting range | Watch out for |
|---|---|---|---|
| Simple profile, one setup | Manual G-code | G54, G43 H01, 0.05 mm/tooth | Wrong tool length offset |
| Curved surfaces, 3-axis | CAM, 3-axis | Stepover 0.5 mm, Ra 0.8–1.6 μm | Scallop left on steep walls |
| Features on 4 sides | CAM, 4-axis | Index 90°, one datum per face | Stack-up between rotations |
| Undercuts, organic shapes | CAM, 5-axis | 0.3 mm stock to leave | Holder collision on deep pockets |
| Aluminum 6061 | Flood or air blast | 3,000–6,000 rpm, 12 mm end mill | Chip packing in deep slots |
| Stainless 304 / 17-4PH | Flood coolant | 80–120 m/min, 0.03 mm/tooth | Work hardening from rubbing |
| Threaded holes | Rigid tapping | Feed = pitch × rpm exactly | Spindle direction and pitch mismatch |
| First article run | Single block | Rapid override 25% | Skipping the dry run |
Program it once, prove it once
A program that has passed a dry run, a first article, and a documented offset check will run the same way on the tenth order. Skipping any of the three is how scrap happens.
Questions engineers ask before programming
What is the difference between G-code and M-code?
G-code controls motion and geometry: G00 rapid, G01 feed, G02 and G03 arcs, G54 work offset, G43 tool length. M-code controls machine functions: M03 spindle on, M05 spindle stop, M08 coolant on, M09 coolant off, M30 program end.
Both appear in the same block stream. A tool change usually combines an M06 with a T number and a G43 H offset on the next line.
Can a beginner program a CNC machine safely?
Yes, if the first jobs are simple and the dry run is mandatory. Start with one-setup parts in aluminum, manual G-code for profiles and drilling, and single block for every new program.
Move to CAM and multi-axis work only after the basics of offsets, tool length, and work coordinates are solid.
How long does it take to program a complex part?
A simple 3-axis bracket with ten features takes roughly one to three hours including simulation and the setup sheet. A 5-axis part with organic surfaces and tight tolerances can take one to three days because of toolpath review and fixture planning.
The programming time is usually a small fraction of the total lead time once the part goes into production.
What tolerance can a well-written program hold?
On a rigid 5-axis machining center with good tooling, ±0.005 mm is achievable on critical features. General dimensions typically run at ±0.05 mm to ±0.1 mm depending on material and setup.
Surface finish follows the toolpath: Ra 0.8–1.6 μm is a normal fine finish, and Ra 0.2–0.8 μm needs a dedicated finishing pass with a sharp tool.
Should I program in CAM or at the machine?
CAM for anything with curves, multiple setups, or more than a few dozen toolpath moves. At the machine for simple drilling, facing, and repair work, where setting up a CAM session takes longer than typing the cycle.
Many shops do both, and hand-edit the CAM output for safety.
How does an outsourced shop keep my design files secure?
Ask for a signed NDA before files move, and confirm the shop holds an information security certification. GreatLight works under ISO 27001:2022 controls, and uploads through our quotation page are kept confidential.
Keep the CAD release and the CAM file on the same revision so the shop is never cutting an old model.
Send the CAD file and let our engineers review the program
We return a quotation and a free DFM analysis within 12 hours, flag any feature that is hard to program, and start production in as little as 24 hours.
12-hour quoteNo minimum order100% inspection before shipment