CNC Machining Understanding: The Decoding Process
This guide is for engineers and buyers who send a CAM file to a shop and want to know what happens next. It walks through the decoding process: how CAM toolpaths become G-code and M-code, how a control reads that code line by line, and where parts go wrong. Read it before you approve a setup sheet.

In this article
- 1
- 2
- 3
- 4
- 5
- 6
- 7
Key takeaways
What the decoding process actually converts
A CAM system stores your part as toolpaths: a cutter moving through space with a feed rate, a spindle speed, and a stepdown. The control on a machine tool cannot read any of that. Decoding, sometimes called post-processing, is the step that rewrites toolpaths as a numbered list of blocks the control executes in order. Each block is one instruction. Read the list top to bottom and you have the exact motion of the machine.
The output is G-code for motion and M-code for machine functions. G00 is a rapid move, G01 a straight feed, G02 and G03 arcs clockwise and counterclockwise. M03 starts the spindle forward, M08 flood coolant on, M30 program end and reset. A typical block looks like N120 G01 X45.2 Y-12.8 Z-3.4 F380. That single line tells the machine to move to a point at 380 mm/min.
Two families sit behind the syntax. ISO code is the common baseline. Fanuc, Siemens, Heidenhain, Mitsubishi, and Haas each extend it and each expects slightly different wording. A program posted for one control may run on another, or it may alarm on line 20. That is why decoding is tied to a machine, not to a CAD file.
- 1G-codeMotion, offsets, compensation, canned cycles.
- 2M-codeSpindle, coolant, tool change, program stop.
- 3Post-processorThe translator between CAM output and one control dialect.
How a control reads a decoded program
A control reads blocks in order and holds a state. If G01 appears once, the next block without a G word still cuts in feed. The same applies to the work offset, the plane, and the feed rate. This is called modal state, and it is the single most common source of confusing behavior on the floor. A program that runs perfectly in simulation can cut air, or cut the vise, because a modal value was left over from the previous tool.
Decoding has to declare three things before the first cut. The work offset, usually G54, tells the control where part zero sits in machine travel. The tool length offset, G43 H01, tells it how long tool 1 is. Cutter compensation, G41 or G42 with a D register, tells it which side of the path the radius sits on. Miss any one and the first article is scrap.
Then comes the geometry. Arcs need a plane: G17 for XY, G18 for XZ, G19 for YZ. Feed modes matter too. G94 is feed per minute, G95 feed per revolution. On a lathe, G95 at 0.15 mm/rev is a sensible roughing feed for mild steel; the same number in G94 would be 0.15 mm/min and the tool would rub. Units are declared by G20 for inches and G21 for millimeters, and the file must match the control setting.
- 1Modal trapsA leftover G41 or wrong plane carries into the next operation.
- 2Offsets firstG54, G43 H, and D registers before any cutting move.
- 3Unit checkG20 vs G21 mismatch scales every coordinate by 25.4.
Where decoding breaks down in real shops
Post-processors are written for a machine model, not for every option on that machine. Add a rotary table, a bar feeder, or a high-pressure coolant unit and the post needs editing. The usual failure is not a crash. It is a wrong retract height, a tapping cycle that ignores a floating holder, or a tool change that calls the wrong pocket. These cost setup time on every run, not just the first.
Toolpaths also carry assumptions the code cannot express. A 3-axis program cannot reach an undercut no matter how clean the code is. A 5-axis program with a singularity near the tool axis will jerk, and the fix is in the CAM strategy, not in the G-code. When a first article shows chatter on a thin wall, the answer is usually a changed stepdown or a support, not a different feed word.
Tolerance is the other boundary. Decoded coordinates are exact, but the machine, tool, and material are not. Holding ±0.005 mm means the program has to leave finishing stock, use cutter compensation tied to a measured tool, and include in-process checks. A program that cuts to nominal in one pass may pass inspection once and fail on the next tool change.
When a decoded program is good enough to release
Release a program when three things are true. The first article measures inside tolerance on every critical feature. The setup sheet matches what is actually on the machine, including offset values and tool numbers. And a second operator can run the job from that sheet without asking questions. If any of the three is missing, the program is a draft, not a release.
Some jobs do not need a full decode cycle. A one-off bracket with ±0.1 mm callouts can run from a conversational control or a manual program in less time than it takes to post and simulate. The tradeoff flips once you expect three or more parts, or when a feature sits below ±0.02 mm. Then the setup cost of a proper post, prove-out, and archive pays back on the first repeat.
For parts we machine at GreatLight, the decoded program is paired with a first-article report on request. In-process monitoring runs through the batch, and 100% inspection happens before shipment. That is how the code stays tied to the drawing after the setup is torn down.
- 1Release criteria
- 2Skip the full cycle
- 3Always decode properly
Step by step: decoding a part from CAD to first cut
- 11. Freeze the model and the tolerance calloutsLock the revision before CAM starts. Mark every dimension tighter than ±0.05 mm and every surface below Ra 0.8 μm. These drive stock allowance and finishing strategy. Changing the model after posting forces a full re-decode.
- 22. Plan setup and work offsetsDecide how many setups the part needs and where zero sits in each. On a 3-axis job, put Z zero on the top face. On a mill-turn part, keep one datum through both spindles. Write the offsets into the setup sheet, not into a machinist's memory.
- 33. Select the post-processor and verify its headerMatch the post to the exact machine and control. Check the header for units, G54 through G59, tool change format, and safe Z. A header that retracts to Z100 in inch mode on a metric machine lifts the tool 100 mm, which may not clear the fixture.
- 44. Post and read the first 30 blocksLook for the unit word, the work offset, tool length compensation, and spindle direction. A missing G43 or an M04 instead of M03 is visible in seconds and saves a crash. Confirm the rapid plane clears the tallest feature plus 5–10 mm.
- 55. Simulate, then prove on the machine without stockRun the CAM simulation for gouges and holder collisions. Then dry run on the machine at rapid override down to 25%, single block on, distance-to-go displayed. Watch the tool position at every tool change before letting it cut.
- 66. Cut the first article and measure before the secondCut one part, then measure the critical features. For ±0.005 mm work, inspect and adjust the D register, then re-cut. Do not run the full batch on an unproven program; a single offset error multiplied by 200 parts is expensive.
- 77. Archive the proven program with its setup sheetSave the posted file, the offset values, the tool list, and the inspection result together. On a repeat order the next operator loads a known-good program instead of re-posting, which removes the decode risk entirely.
Common decode faults and how they show up
Use this when a first article behaves strangely.
| Symptom | Likely cause | Fix |
|---|---|---|
| Part cut 25.4× too large | G20/G21 unit mismatch | Post in the control's unit system |
| Tool dives at first move | Missing G43 or wrong H register | Add length comp before cutting |
| Mirrored feature | G41/G42 swapped | Match comp side to climb milling |
| Arc alarms out | Wrong plane G17/G18/G19 | Set plane before G02/G03 |
| Thread pitch wrong on lathe | G94 used where G95 belongs | Switch to feed per revolution |
| Chatter on thin wall | Stepdown too deep for the setup | Reduce radial depth, add support |
| Second part out of tolerance | Tool wear, no comp update | Measure and adjust D register |
CNC machining understanding: decoding questions
Is the decoding process the same as post-processing?
In most shops, yes. Decoding and post-processing both describe turning CAM toolpaths into a machine-specific G-code and M-code file.
Some teams use decoding for the wider chain, including offset setup and prove-out, and post-processing only for the CAM export step. The code itself is the same either way.
Can I run a program posted for one machine on another?
Sometimes, but never without checking. Controls differ in canned cycles, tool change format, and how they handle subprograms and macros.
Compare the header and the first tool change block. If the two controls are from different builders, re-post instead of editing by hand.
Why does my simulation pass but the real part fail?
Simulation checks the toolpath, not the machine state. It does not know your vise, your tool holder, or whether G54 was set to the right corner.
Most real failures come from offsets, tool length, or a fixture collision that the CAM model never included.
How much stock should the decoded program leave for finishing?
For aluminum, 0.3–0.5 mm radial and 0.1–0.2 mm axial is a normal finishing allowance. For stainless and tool steel, 0.2–0.3 mm radial works better because the load is higher.
Below ±0.02 mm, leave enough for a spring pass and plan to adjust cutter compensation after measuring the first article.
Do you need the native CAM file or just the STEP model?
A STEP or IGES model plus a 2D drawing with tolerance callouts is enough. We build our own toolpaths and post them to our machines.
Native CAM files are useful when you want the same toolpath strategy repeated exactly, but they are not required for quoting or production.
How does the decode step affect lead time?
Quotation and free DFM analysis come back within 12 hours, and production can start within 24 hours after approval. Parts ship in 3–5 days for typical jobs.
A new program with tight tolerances adds a prove-out cycle for the first article. Sending complete tolerance callouts with the model removes most of that delay.
Send a model and get a decoded, proven process
Upload your STEP file and tolerance drawing. We return a quote, free DFM notes, and a setup plan within 12 hours.
12-hour quote100% inspectionNo minimum order