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

Get Instant Quote

Machining fundamentals

CNC G code programming: how machine motion becomes a part

A practical explanation of what G code actually controls, what a CAM post-processor keeps or drops, and where the limits of the language sit. Written for design engineers and buyers who review programs, tolerances, and setup sheets, so they can tell a sound program from a risky one.

ISO 6983 word addressModal states±0.005 mm capability
CNC G code programming example for lathe turning and cutter motion
Core principle

What CNC G code programming actually controls

A G code program is a list of word-address blocks. Each block holds letters followed by numbers: G for preparatory functions, X Y Z for linear position, I J K for arc centers, F for feed rate, S for spindle speed, T for tool selection, M for machine functions. The control reads the block, resolves it against its current modal state, and moves the axes to the commanded point. Nothing in the text is geometry. Geometry lives in the motion the control calculates.

That distinction matters when you review a program. A line like G01 X50.0 F800 does not say the tool is at X50. It says the tool should arrive at X50 while feeding at 800 mm/min. The control decides how, subject to acceleration limits and look-ahead. Two machines running the same text can produce different surface finishes.

Modal state is the part most people underestimate. G00, G01, G02, G03, G17, G40, G43 and the active feed all persist until another code replaces them. Skip a G40 after a cutter compensation block and the next tool path inherits the offset. The result is a gouge that appears twenty blocks later, far from the line that caused it.

So a program is not a drawing. It is a state machine with a tool attached. Reading it means tracking what the control believes at each line, not what the coordinates look like in isolation.

Machine language

How G codes and M codes divide the work

G codes describe where the tool goes. M codes describe what the machine does while the tool is there or before it moves. G01 feeds in a straight line, G02 and G03 cut arcs, G81 through G89 handle drilling and boring cycles, G28 sends axes to reference position, G54 to G59 select work coordinate systems. Those are the codes that shape metal.

M codes sit on the machine side. M03 and M04 start the spindle clockwise or counterclockwise, M05 stops it, M06 changes the tool, M08 and M09 control coolant, M30 ends the program and rewinds. Some M codes are builder-specific, which is why M07 on one control may do nothing on another. Always check the machine manual before trusting an M code you have not run.

The split matters for cycle time. Moving a tool with G01 is cheap. Every M06 tool change costs seconds of non-cutting time, and on a 16-tool program that adds up across a batch. Grouping features by tool, not by drawing order, is one of the few programming decisions that reliably pays back.

Spindle and feed codes also carry no physics. S12000 and F2000 are commands, not outcomes. Whether the cutter survives depends on chip load, radial engagement, and material hardness, which the program does not contain unless the programmer put it into the CAM parameters.

CAM and post-processors

Where CAM output stops being G code programming

CAM software does the geometric work: toolpath strategy, stepover, rest machining, collision checks. What reaches the machine is the post-processed output, and that output is shaped by the post-processor configuration, not by the CAD model. Two shops cutting the same part from the same model can send very different programs to identical machines.

A post-processor decides arc output format, whether I J K or R is used, how tool length compensation is applied, decimal precision, and which canned cycles get expanded into longhand moves. Get the post wrong and the machine still runs. It just runs slowly, or leaves witness marks where a cycle should have retracted cleanly.

This is where hand editing enters. A programmer may raise a feed, insert a dwell with G04, split a deep pocket into depth passes, or add an M00 stop so an operator can check a feature. Those edits are where most crashes originate, because the changed block usually breaks a modal assumption made earlier in the file.

The practical rule: treat post output as a draft. The program is not finished until it has been verified against the setup sheet, the tool list, and the actual stock condition. Simulation helps, but it models the machine, not the fixture.

Boundaries

Where the language runs out of precision

G code carries coordinates, not tolerances. The control interpolates along the commanded path and holds position within its servo and encoder resolution. On our machines that lands at ±0.005 mm on a qualified process, but the program itself does not guarantee it. Fixture rigidity, tool runout, thermal drift, and material springback decide what the part measures.

Every axis move is a trade between speed and accuracy. Look-ahead smoothing rounds corners to keep feed rates up. Tighten the tolerance band and the control slows down, sometimes by half. That is why a fine-finish pass often costs more cycle time than the roughing that removed most of the material.

Cutter compensation, G41 and G42, is the classic edge case. It works well on straight walls and generous radii. On internal corners smaller than the tool radius, the control has to invent a path, and the result can be a small gouge or an over-cut. CAM rest-machining handles these corners better than compensation alone.

Thread milling, deep pockets, thin walls, and features under 0.5 mm wide all push against what the language can express cleanly. They are machinable, but the program needs smaller stepovers and slower feeds, and someone has to decide where the extra time is worth it.

Shop floor

What we check before a program cuts metal

Simulation catches gross collisions. It does not catch a program that will chatter, so the first run happens on the real machine with the real fixture, at reduced feed and spindle override. We watch the load meter and the sound, then step up to the programmed values. That is faster than trusting the simulation and scrapping the first part.

Setup sheets matter as much as the code. Tool numbers, offsets, work coordinate origin, and stock size all have to match the program's assumptions. A G54 origin set 0.3 mm off shifts every feature on the part, no matter how clean the toolpaths look.

Verification is layered on purpose. Raw material is checked before cutting, dimensions are monitored in process, and every part is inspected before shipment, with reports on request. On a 10,000-part run the program is frozen early, because changing a feed mid-run invalidates the data behind the first article.

For prototypes the calculus flips. We would rather edit the program between parts than lock it. No minimum order quantity means a single piece can justify a custom setup, and the same programmer who wrote the roughing pass can adjust the finishing strategy after measuring the first article.

Decision table

When to hand-edit a program and when to leave it alone

Use this to decide who touches the file and how much risk the change carries.

SituationActionRisk
Feed rate too conservative on proven toolpathEdit F value at the machineLow, single block
Deep pocket needs more depth passesRe-post from CAMLow, regenerated
Internal corner smaller than tool radiusSwitch to rest machining in CAMMedium, retest part
Tool change order causing long idleReorder operations in CAMMedium, check clearances
Fixture moved after first articleReset G54 origin, no code changeHigh if unverified
Thin wall deflecting on finish passReduce stepover, slow final passMedium, watch chatter
Feature needs in-process checkInsert M00 stop and re-probeMedium, operator dependent
Five-axis tilt on a narrow slotVerify post output, then dry runHigh, collision risk

The short version

Trust the code for geometry and the setup sheet for position. If a feature is tighter than ±0.005 mm or the corner is smaller than the cutter, change the process in CAM, not the numbers at the control.

FAQs

Common questions

Does every CNC machine read the same G code?

No. ISO 6983 standardizes the common word addresses, so G00, G01, G02 and G03 behave the same almost everywhere. Beyond that, builders diverge. Canned cycles, M code assignments, and five-axis commands are control-specific, and a Fanuc post will not run unmodified on a Siemens or Heidenhain control.

The practical answer is that a program is portable only with a matching post-processor. Switching machines without re-posting is how a working program turns into a crash.

Can a program hold ±0.005 mm on its own?

The program defines the commanded path. Holding that path depends on the machine, the tool, the fixture and the material. Servo resolution and encoder feedback set the floor, but thermal growth over a long run can move the part further than the tolerance band.

That is why in-process checks exist. On a qualified process our machines reach ±0.005 mm, and every part is inspected before shipment. If a feature needs tighter than that, it usually belongs on a grinder or EDM.

How much does manual editing actually save?

Usually less than people expect. Raising a feed by 20 percent on a proven path is a real gain with almost no risk. Rewriting a roughing strategy by hand rarely beats re-posting from CAM, because the hand version loses look-ahead tuning and rest-machining logic.

The safe edits are small and local: a feed override, a dwell, an added M00 stop, a tool change moved earlier. Anything that touches geometry should go back through CAM.

Why does the same program cut differently on two machines?

Acceleration limits, look-ahead depth, and servo tuning differ. A control with deeper look-ahead smooths corners to keep the feed rate up, which can round a sharp internal corner. A machine with a lighter structure will chatter at the same feed that runs quiet on a heavier one.

Spindle runout and tool holder condition add to it. Two nominally identical machines with different tool holders can hold different surface finishes from the same text.

Do you need the CAD file, or can you work from a drawing?

Either works for quoting. A 3D model is faster and removes ambiguity on curved surfaces, blends, and draft. A 2D drawing with tolerances, material and finish notes is enough for many turned parts and simple milled features.

We return a quotation and a free DFM analysis within 12 hours, and note anything that will be hard to hold before the program is written. Uploads are secure and confidential, and an NDA is available on request.

What happens when a program fails mid-run?

The machine stops, the tool is inspected, and the program is checked against the setup sheet before restart. Most failures trace back to a modal assumption broken by an edit, a wrong offset, or a tool that wore past its limit rather than a bad toolpath.

We keep historical late-delivery probability below 2 percent, and parts ship in 3 to 5 days on standard work. Restarting after a verified fix usually costs less than a scrapped batch.

Send us the part, we will handle the code

Upload a model or drawing and get a quotation with free DFM analysis within 12 hours. Production can start within 24 hours, from one prototype to 10,000+ part runs.

12-hour quote±0.005 mm100% inspection

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