CNC Encoding Basics
How a CAD model becomes motion: G-code words, M-code commands, offsets and units. Written for engineers and buyers who need to judge a program, a drawing or a quote before metal is cut.

Key takeaways
What CNC encoding actually is
CNC encoding is the step where a toolpath becomes text a machine control can read. The control does not see a model. It sees lines, and each line is a set of words. A word is a letter plus a number: G01 X42.5 Y18.0 F250. The letter says what kind of information follows, the number gives the value.
That is the whole idea. Everything else in cnc encoding basics is a convention built on top of it: which letters exist, which numbers are legal, and what the control does when a line is incomplete. Once you can read a block of text and picture the cutter moving, you can review a program instead of trusting it.
Two families of codes do most of the work. G-codes describe motion and machine state. M-codes switch things on and off, such as spindle rotation, coolant and program stop. Fanuc-style controls dominate milling and turning, so most shop-floor conversations use that vocabulary even when the machine is another brand.
The practical reason this matters to a buyer is cost. A program that is written to respect the setup, the tool list and the tolerance band runs in one pass. A program that fights the setup adds a second fixture, a second probe cycle, or a scrapped batch.
- 1BlockOne line of the program, ended by a line number or end-of-block character.
- 2WordOne address letter plus its value, for example T07 or S8000.
- 3ModalStays active until another code in the same group replaces it.
- 4Non-modalApplies only to the block where it appears.
G-code groups and how motion codes behave
Motion codes sit in group 1. G00 moves at rapid traverse, G01 feeds in a straight line, G02 and G03 cut arcs clockwise and counterclockwise. Only one of them can be active. If a block contains no motion code, the control repeats the last one, which is why a line like X50.0 Y20.0 still moves the tool.
Arc blocks need more than an endpoint. G02 X50.0 Y20.0 I10.0 J0.0 describes the arc center relative to the start point. Get I and J wrong and the control either alarms out or cuts a bulge you did not draw. Many controls also accept a radius address R, but R cannot describe an arc larger than a half circle.
Feed rate is modal too. F250 means 250 mm per minute in G94 mode, or 0.25 mm per revolution in G95 turning mode. This is the single most common unit trap in cnc encoding basics. A program written for feed per minute run on a control set to feed per revolution will either crawl or break a tool.
Rapid moves are not cutting moves. G00 should stay at a safe height until the tool is positioned, then G01 plunges. CAM software does this automatically, but hand edits often delete the retract line, and that is where the deep gouge comes from.
- 1G00 rapidPositioning only, never into stock.
- 2G01 linearStraight feed cut at the programmed F value.
- 3G02 / G03Clockwise and counterclockwise arcs with I, J, K or R.
- 4G17 / G18 / G19Selects the plane for arc interpolation and cutter compensation.
M-codes, spindle and coolant
M-codes handle the non-motion side of the cycle. M03 starts the spindle clockwise, M04 counterclockwise, M05 stops it. M08 and M09 control flood coolant. M06 calls a tool change, usually paired with a T number that was staged earlier in the program.
Some M-codes are control-specific. M30 ends the program and rewinds. M00 is an unconditional stop. M01 is an optional stop that only works when the operator enables it, which is why it appears before a manual measurement. Two shops can run the same file and get different behavior if one control treats a code differently.
Order matters inside a block. Spindle start should come before the first feed move into material, and coolant before the cutter touches stock. Reversing that order is not always fatal, but on deep pockets it means the first few millimeters cut dry.
On mill-turn and multi-axis machines the code list grows. Synchronous codes coordinate two turrets or a subspindle, and bar feed or parts catcher commands are M-codes as well. None of it changes the reading method: letter, number, state.
Offsets, units and work coordinates
The program says where the tool goes. The offsets say where the part is. A work offset, usually G54 through G59, shifts the machine coordinate system to the corner of the stock or to a fixture datum. A tool length offset tells the control how long the current tool is compared with the reference.
If a part is 0.05 mm off after a tool change but correct before it, the tool length offset is the first thing to check. If every feature is displaced by the same amount, the work offset is wrong. Those two symptoms separate the two systems, and they are worth remembering on the floor.
Units are declared with G20 for inches and G21 for millimeters. The declaration is modal, so one line at the top of the program sets the whole file. A control that boots in inches and reads a metric program will move 25.4 times too far, which is why the first block of a proven program is never edited casually.
On our own 127 high-precision CNC machines, including 16 simultaneous 5-axis machining centers, we set work offsets from the fixturing model and verify with a probe before the first cutting pass. The tolerance window is ±0.005 mm (±0.0002 in), so an offset error of a few hundredths is already a reject.
Where CNC encoding gets hard
Simple 2.5D work is forgiving. Pockets, profiles and drilled holes can be hand-edited without much risk. The picture changes with 3D contoured surfaces, thin walls and five-axis tool vectors, where the control must interpolate between many short linear blocks and small mistakes accumulate into visible scallops.
Tool runout, material springback and thermal growth are not in the program. A titanium pocket and an aluminum pocket can use the same code and produce different walls. That is why finish passes are usually kept light, and why a program that works in 6061 is not assumed to work in Inconel or TC4 (Ti-6Al-4V).
Simulation catches collisions, not strategy. A verified program can still chatter, burn a cutter or miss a tolerance because the stepover, the tool stick-out or the workholding was wrong. Simulation answers whether the machine will crash, not whether the part will be good.
Where cnc encoding basics stop being enough is multi-setup work. Once a part needs a second op, a re-datum, or a mill-turn handoff, the risk moves from the code to the process plan. Reviewing the program alone will not tell you whether the part can hold ±0.005 mm.
Code families and what each one controls
Use this when you review a program block by block.
| Code group | Typical values | What it sets | Watch for |
|---|---|---|---|
| Motion | G00 G01 G02 G03 | Path shape and feed | Missing I or J in arcs |
| Plane | G17 G18 G19 | Arc and comp plane | Wrong plane on a lathe |
| Units | G20 G21 | Inch or millimeter output | Mixed values after an edit |
| Feed mode | G94 G95 | Per minute or per rev | Lathe feed changed by hand |
| Compensation | G40 G41 G42 | Cutter radius offset | Comp reversed on a climb cut |
| Work offset | G54–G59 | Part origin in the machine | Stale offset from last job |
| Tool change | T and M06 | Next tool and swap | Tool staged after the call |
| Coolant | M08 M09 | Flood on and off | Dry first cut in deep pockets |
When to trust the program, when to trust the plan
If the part is 2.5D, one setup and aluminum, reading the G-code is enough. If it is five-axis, thin-walled or needs a second op, review the process plan first and the code second, because that is where the tolerance is won or lost.
Questions engineers ask next
Is G-code the same as CNC encoding?
G-code is the most visible part of CNC encoding, but the term covers the whole chain: CAD model, CAM toolpath, post-processor output, offsets and the machine setup. Two shops can run identical G-code and produce different parts because the offsets and the fixturing differ.
How long should a program take to prove out?
For a one-off prototype, a dry run plus a single-block first article is usually enough. For a repeating production run, the first part is inspected against the drawing and the report is kept with the program revision so the next run starts from a known state.
Can you machine from a drawing instead of a 3D model?
Yes, for parts that are defined by dimensions and simple features. A 2D drawing is enough for many turned parts and plate work. Complex contoured surfaces are faster and safer from a 3D model because the toolpath is generated from the same geometry the drawing describes.
What tolerance can a proven program hold?
Across our shop the working tolerance is ±0.005 mm (±0.0002 in), with surface finish from Ra 0.2–0.8 μm on fine work up to Ra 1.6–3.2 μm as-machined. The program has to be matched by the machine, the tool and the inspection method to reach those numbers on a real part.
Do you need an NDA before sharing a model?
No, but we can sign one. Uploads are handled as confidential and an NDA is available on request. Files are used only for the quotation and the parts themselves, and inspection reports are issued on request.
What do you need to quote a program or a part?
A 3D model or a dimensioned drawing, the material, the quantity and the critical tolerances. Quotation and a DFM analysis come back within 12 hours, and production can start within 24 hours of approval. No minimum order quantity applies, from one prototype to 10,000+ part runs.
Send the model, get a manufacturable answer
Upload a model or drawing and our engineers return a quotation with DFM notes within 12 hours. Every part is inspected before it ships, and the program stays with the job for the next run.
12-hour quote100% inspectionNo minimum order