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

Get Instant Quote

CNC programming guide

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.

±0.005 mm tolerance3-axis to 5-axisG-code and CAM
how to cnc machine program workflow on a machining center
Key takeaways

What matters most

The setup sheet comes firstWorkholding, stock size, and zero point decide the program before any G-code is typed.
Cut air before you cut metalA dry run at rapid override 25% catches most collisions for less than ten minutes of time.
Feeds follow the chipChip load per tooth, not spindle speed alone, controls tool life and surface finish.
Offsets are the last variableVerify tool length and work offsets on the machine, then lock them for the run.
Step 0

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.

  • 1
    Datum firstPick the face that locates in the fixture as your program zero.
  • 2
    Tolerance mapList every dimension under ±0.05 mm and inspect those features in-process.
  • 3
    Access checkFlag any feature that needs tool access from more than one direction.
Step 1

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.

  • 1
    Small radius ruleThe finishing tool diameter must be smaller than twice the smallest internal radius.
  • 2
    Post-processor matchConfirm the post against the actual control before the first run.
  • 3
    Stock accuracyModel the real stock; an oversized blank changes the first roughing pass.
Step 2

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.

  • 1
    Chip load over rpmSet feed per tooth first, then calculate the spindle speed.
  • 2
    Coolant by materialAluminum tolerates air blast; stainless, titanium, and tool steel need flood.
  • 3
    Tap syncMatch feed to pitch exactly or the thread will strip.
Verification

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.

  • 1
    First articleMeasure the tight features and record the offsets that produced them.
  • 2
    Load meterKeep roughing under about 70 percent of the spindle load rating.
  • 3
    Revision controlOne proven file, one revision number, one folder.
Workflow

How to CNC machine program: 7 steps to a proven first cut

  • 1
    1. 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.
  • 2
    2. 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.
  • 3
    3. 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.
  • 4
    4. 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.
  • 5
    5. 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.
  • 6
    6. 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.
  • 7
    7. 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.
Reference

Starting parameters and where each method fits

Use these as first-cut ranges, then adjust to the setup rigidity and tool grade.

WorkMethodStarting rangeWatch out for
Simple profile, one setupManual G-codeG54, G43 H01, 0.05 mm/toothWrong tool length offset
Curved surfaces, 3-axisCAM, 3-axisStepover 0.5 mm, Ra 0.8–1.6 μmScallop left on steep walls
Features on 4 sidesCAM, 4-axisIndex 90°, one datum per faceStack-up between rotations
Undercuts, organic shapesCAM, 5-axis0.3 mm stock to leaveHolder collision on deep pockets
Aluminum 6061Flood or air blast3,000–6,000 rpm, 12 mm end millChip packing in deep slots
Stainless 304 / 17-4PHFlood coolant80–120 m/min, 0.03 mm/toothWork hardening from rubbing
Threaded holesRigid tappingFeed = pitch × rpm exactlySpindle direction and pitch mismatch
First article runSingle blockRapid 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.

FAQs

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

Follow

More machining notes

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