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

Get Instant Quote

CNC programming basics

What Program Do CNC Machines Use?

Short answer: a CNC machine runs g-code, a plain text file of motion and switch commands. The longer answer is about who writes that file, which dialect the controller accepts, and how a CAD model becomes a toolpath. This page is for engineers and buyers who need to judge a shop's programming chain, not just its spindle.

G-code and M-codeCAM outputPost-processorsController dialects
what program do cnc machines use
The file itself

What a CNC program actually contains

A CNC program is a text file. Each line is one block, and each block holds a letter address: G for preparatory commands, M for machine functions, X Y Z for linear moves, I J K for arc centers, F for feed, S for spindle speed, T for tool number. The controller reads the file top to bottom, one block at a time, and executes it. There is no compiler and no runtime library. The file is the program.

Almost every line you see is a motion command. G00 moves at rapid traverse to a position without cutting. G01 cuts in a straight line at the programmed feed. G02 and G03 cut arcs clockwise and counterclockwise. G81 through G89 cover drilling, boring, and tapping cycles. Everything else supports those moves: tool changes, coolant on and off, spindle start, program stop.

The M-codes are the machine-side switches. M03 starts the spindle forward, M05 stops it, M08 floods coolant, M09 kills it, M06 changes the tool. M30 ends the program and rewinds. A block like G01 X50.0 Y20.0 F250 is one straight cut at 250 mm/min. That is the whole idea.

File size surprises people. A roughing and finishing cycle on a 300 mm aluminum bracket might run 3,000 to 15,000 blocks. A five-axis impeller with a dense finishing pass can pass 400,000 blocks. Controllers stream these from memory or drip-feed them over a serial link, which is why block processing speed matters on old machines.

CAD to metal

How a CAD model becomes a CNC program

Nobody types that many lines by hand. The path is CAD to CAM to post-processor to controller. The engineer models the part in CAD, then imports a STEP or IGES file into CAM software. In CAM, they choose stock size, set the work origin, pick tools from a library, and define roughing and finishing strategies. The CAM kernel computes the toolpath and writes a cutter location file.

The cutter location file is machine-neutral. It knows the tool tip position in part coordinates, but it does not know that this particular machine has a rotary table on the right side, or that its controller wants a decimal point in every coordinate. That translation is the post-processor's job.

This is where a lot of quoting errors come from. A shop can own good CAM seats and still produce scrapped parts if the post-processor was never validated for that machine. When we onboard a new five-axis center, we cut a test artifact and check the rotary offsets, tool length compensation, and retract moves before the machine touches a customer part. Without that step, the first article becomes the test.

For simple turned parts, the chain shortens. Many lathes are programmed at the control with a few dozen blocks of G71 roughing and G70 finishing cycles. A shaft with two diameters and a thread does not need a CAM seat.

Dialects

Why the same part needs a different program per machine

G-code is standardized on paper by ISO 6983, but no two controllers implement it identically. Fanuc, Siemens, Heidenhain, Mitsubishi, and Haas each have their own extensions and quirks. Some want G43 H01 for tool length offset and some accept G43 without the H word. Some use G54 through G59 work offsets, some allow G54.1 P1 for extended offsets on pallet systems.

Arc formatting differs too. Fanuc accepts I J K center offsets; Heidenhain conversational format wants radius and direction. A program written for a Haas mill will usually need edits before a Siemens 840D runs it cleanly. This is why shops keep a post-processor per machine family, not one universal post.

Rigid tapping is a good test case. On Fanuc, G84 with an M29 spindle-orientation command works. On other controllers, the same hole needs G84.2 or a floating tap holder instead. If the post is wrong, the tap breaks and the part may be scrapped.

The practical consequence for buyers: if you move a part between two shops, do not assume the program transfers. Send the 3D model and the drawing, not the g-code. From the model, each shop regenerates toolpaths that match its own machines and fixtures.

Boundaries

When g-code is the wrong tool

G-code is a low-level language. It describes motion, not intent. That is a strength for deterministic cutting and a weakness for anything that needs decisions during the cycle. If you want the machine to measure a feature and adjust the next pass by the result, plain g-code will not do it alone.

That job goes to macro programming, usually Fanuc Macro B, or to a probing cycle from the machine builder. A macro can read a probe result into a variable and shift a work offset. This is common on high-mix work where casting dimensions vary from lot to lot. It adds complexity and needs careful testing, so it is worth it only when the tolerance or the scrap cost justifies it.

Parametric CAD and CAM cover a different gap. If a family of brackets differs only in hole spacing, model it parametrically and let CAM regenerate. Hand-editing a g-code file per variant is how mistakes get made.

What g-code does not cover at all: closed-loop decisions based on real-time sensor data, in-process metrology with automatic re-cutting, and adaptive feed control beyond what the controller offers natively. Those are controller features or separate systems bolted onto the machine, not program features.

Shop floor

What this means for a shop's programming chain

At GreatLight we run 127 high-precision CNC machines across three plants, including 16 simultaneous 5-axis machining centers, 12 four-axis mills, and 16 mill-turn centers. Each machine family carries a validated post-processor. That is the part of the chain that customers never see, and it is the part that decides whether a first article lands inside ±0.005 mm.

Programming feeds into the same inspection loop as the machines. Every part is checked 100% before shipment, with raw material checks, in-process monitoring, and final inspection. When a dimension drifts, the fix may be a tool offset in the controller, a change in the CAM stepover, or a new post for a different machine. Knowing which one to change is the difference between a two-hour fix and a two-day investigation.

Materials change the program as much as geometry does. Aluminum 6061 at 6,000 rpm and 2,000 mm/min behaves nothing like Inconel at 40 m/min surface speed. Feeds and speeds live in the CAM tool library and are rechecked at the machine. PEEK and carbon fibre bring their own rules on heat and dust extraction.

We hold ISO 9001:2015, IATF 16949:2016, ISO 13485:2016, and ISO 27001:2022. Those certificates shape how programs are version-controlled, approved, and stored, especially for medical and automotive work where a program change is a documented event.

Decision table

Which programming route fits which job

Match the part to the programming method before you quote

Job typeProgramming routeWhy
Single turned shaft, 2 diametersLathe G71/G70 at the controlDozens of blocks; CAM adds no value
3-axis bracket, moderate pockets3-axis CAM + Fanuc postFast to generate, easy to verify
Deep cavity in a hardened moldHigh-speed CAM with rest machiningSmall stepover, long tool life planning
Impeller or blisk5-axis CAM with collision checkingTool axis control is the whole problem
Casting with variable stockCAM plus macro probingWork offset shifts per part
One-off fixture plateHand-written or CAM-assistedEither works; keep the setup simple
Family of 12 similar bracketsParametric CAD plus CAMOne master, twelve regenerated programs
Prototype in PEEK or InconelCAM with material-specific feedsHeat and tool wear drive the numbers

The short answer, applied

For simple prismatic or turned parts, CAM output with a validated post is faster and safer than hand coding. For five-axis geometry, complex cavities, or variable castings, the programming chain is where the job succeeds or fails, so ask the shop how it validates posts and inspects first articles.

FAQs

Questions engineers ask next

Can I send g-code to a shop instead of a CAD model?

You can, but most shops will not run it. The code is tied to a specific machine, post, and fixture setup. Without those, the shop cannot verify it.

Send the native CAD file plus a drawing with tolerances. The shop regenerates toolpaths for its own machines, which is also how it takes responsibility for the result.

Is g-code the same as GDL or other machine languages?

No. G-code, formally ISO 6983, is the common language for CNC motion. Some builders add conversational layers on top, like Heidenhain Klartext or Mazak Mazatrol, but the controller still converts those into motion commands internally.

If you hear about other formats, they are usually job files for specific software, not controller languages.

Do all CNC machines need a program file?

They need a sequence of commands. On older or simple machines that can be entered at the control panel and stored in memory. On production machines, it arrives as a file over USB, Ethernet, or drip feed.

The format changes. The need for an explicit command sequence does not.

How long does programming take on a typical part?

For a 3-axis machined bracket with a few setups, CAM programming and verification usually take a few hours. A five-axis impeller with collision checking can take one to two days before the first cut.

It depends on geometry and tolerance, not on part size. A small optical mount with tight tolerances can take longer to program than a large loose bracket.

What happens if a program has an error?

Good shops catch it before cutting, through simulation and dry runs. Simulation catches collisions and rapid moves into stock. It does not catch wrong tool offsets or a fixture that was not modeled.

The remaining errors show up at the machine: wrong depth, chatter, or a broken tool. That is why in-process checks and a final inspection matter more than the program review alone.

Does the program affect the surface finish I receive?

Yes. Stepover, feed per tooth, tool nose radius, and finishing strategy set the achievable finish. A 0.2 mm stepover with a small ball tool gives a different surface than a 1 mm stepover.

We work to Ra 0.8–1.6 μm as a standard machined finish, with Ra 0.2–0.8 μm when the drawing calls for it and the geometry allows it.

Send the model, get a program-reviewed quote

Upload your CAD file and drawing. We review geometry, materials, and tolerance before quoting, and send a quotation with free DFM analysis within 12 hours.

12-hour quote100% inspectionNo minimum order quantity

Follow

More from the shop floor

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