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

Get Instant Quote

Engineering explainer

What Is Gcode in CNC Machine Control

Gcode in a CNC machine is the line-by-line instruction set that moves axes, turns spindles, and selects tools. This page walks through how a CAM post turns a 3D model into those lines, how a controller reads them, and where the process breaks down. Written for engineers and buyers who need to judge a program, not just run it.

ISO 6983 word addressG00 to G03 motionPost-processor output±0.005 mm tolerance
what is gcode in cnc machine
Block structure

How Gcode in CNC Machine Lines Is Built

A Gcode program is a list of blocks, and one block is one line of text. Most controllers follow ISO 6983 word address format: a letter addresses a register, a number gives the value. N10 G01 X45.0 Y12.5 F250 is four words in one block. The N number is a sequence label, useful when you restart a program mid-run. G tells the controller the operation mode. X, Y, and Z carry coordinates. F sets feed rate, S sets spindle speed, and T selects the tool.

Modal behavior matters more than beginners expect. Once G01 is called, every following block stays in feed motion until another G motion word replaces it. G90 and G91 decide whether coordinates are absolute from part zero or incremental from the last point. A program that mixes the two without a clear switch will cut in the wrong place. On our 27 three-axis machines and 12 four-axis mills, the first check after loading is always the modal state at the top of the file.

Coordinates are usually written in millimeters or inches depending on G21 or G20. Feed is mm/min in milling and often mm/rev in turning, so the same F value means different things on a mill and a lathe. Units, plane selection with G17 to G19, and cutter compensation with G41 and G42 are all modal. Post-processors handle these switches, but the machinist still reads the header to confirm them before cycle start.

CAM to machine

From CAD Model to Machine Instructions

The chain starts with a CAD model and a defined stock. CAM software compares the two, then calculates toolpaths that remove material without gouging the part or hitting the fixture. The output is not yet Gcode. It is a toolpath in the CAM system's own internal format. A post-processor then translates that toolpath into the dialect your controller expects.

The post-processor is where most problems are born. Fanuc, Siemens, Heidenhain, and Haas controllers share the core G words but differ in canned cycles, tool change syntax, and rotary axis naming. A post written for a 3-axis Haas will not drive a 5-axis Hermle correctly. For simultaneous 5-axis work, the post must also handle RTCP or TCPM so the controller keeps the tool tip on path while the rotary table tilts.

At GreatLight we run 16 simultaneous 5-axis machining centers, 16 mill-turn centers, and 27 three-axis machines. Each machine family has its own verified post. When a job moves from a three-axis mill to a 5-axis center, the post changes and so does the code. The part model does not change, but the program that cuts it does. That is why we treat post verification as a separate step from toolpath review.

Multi-axis

Why Multi-Axis Work Raises the Stakes

On a three-axis mill, the tool axis stays vertical. The program is mostly 2D contours at stepped Z depths, and a mistake usually shows as a wrong depth or a gouged wall. On a 5-axis center, the tool vector tilts while the part rotates. A and B or C axis motion is synchronized with X, Y, and Z inside the same block. If the synchronization is off by a fraction of a degree, the tool tip drifts off the intended surface.

That drift is not always visible in the first pass. It shows up later as an uneven finish, a wall that is not true to the model, or a gouge on a rib that cannot be reworked. Aerospace and automotive parts with deep pockets, undercuts, and compound angles are the classic case. They often cannot be reached in three setups on a three-axis machine, so the program has to carry the full rotary motion.

RTCP, sometimes called TCPM on other controls, keeps the programmed point at the tool tip regardless of how the rotary axes move. Without it, the CAM system has to calculate the offset itself, and small post errors become large surface errors at long tool lengths. On our 5-axis centers with a Ø400 mm rotary table, we always confirm RTCP is active before the first cutting move. If it is not, the program is paused and the post is corrected.

Reading and checking

How Engineers Read and Verify a Program

Reading Gcode by eye is still useful, even with simulation tools. Start at the header: units, work offset, plane, and modal state. Then follow the tool changes and confirm each H and T number matches the tool list. A wrong H number is one of the most common causes of a crash because the machine trusts it completely.

Next, check the approach and retract moves. G00 blocks near the part are where collisions happen. Confirm the clearance plane is above the stock and the fixture. On deep cavities, watch for the retract height dropping as the cutter follows the floor. A program that clears the part at the start can still hit a clamp halfway through.

Simulation catches most of this, but it uses the same stock and fixture model you gave it. If the model is wrong, the simulation is wrong. We run a dry pass or a single-block run on the first article of a new program, especially on 5-axis jobs and on parts larger than 1,000 mm. On our 4,000 mm travel machines, a dry run costs minutes. A collision costs a spindle.

Limits

Where Gcode Stops Being the Whole Story

Gcode describes motion, not intent. It does not know the material hardness, the tool wear state, or whether the stock is 1 mm oversize. A program that cuts 6061 cleanly may chatter in 17-4PH stainless unless feed and speed are adjusted. The code is the same, the result is not.

Controllers also vary in how they look ahead. Some buffer hundreds of blocks and smooth the motion to hold feed through corners. Others stop at each block, which leaves witness marks on a finish pass. High-speed machining options and NURBS interpolation change the surface result without changing a single coordinate. When a finish is not meeting Ra 1.6 μm, the first question is often the control mode, not the Gcode.

Finally, Gcode does not carry inspection data. It cannot confirm that the part is within ±0.005 mm. That comes from in-process measurement and final inspection. A clean program is a starting point, not proof of a good part. We inspect 100% of parts before shipment and can supply reports on request.

Common words

Core G and M Words and What They Do

A short reference for the words that appear in almost every milling program. Turning programs reuse most of these and add cycles such as G71 and G76.

WordMeaningTypical useWatch out for
G00Rapid positioningMove clear of the partNo cutting feed; fixture collisions
G01Linear interpolationStraight cuts at set feedModal until replaced
G02 / G03Clockwise / counterclockwise arcRadii and filletsI, J, K or R must match the arc
G17 / G18 / G19Plane selectionSets arc plane XY, XZ, or YZWrong plane bends the arc
G20 / G21Inch / millimeter unitsHeader of every programMixed units scrap the part
G41 / G42Cutter compensation left / rightOffset for tool wearComp must be cancelled with G40
G43Tool length offsetApply H offset after tool changeWrong H number cuts too deep
M03 / M05Spindle on / stopStart and end of cutDirection depends on tool hand
M08 / M09Coolant on / offFlood or mistCoolant left on wastes and rusts
M30Program end and rewindLast block of the fileMoves axes home on some controls

When to Trust the Code and When to Question It

If the part is simple and the post is proven, run the program and check the first article. If the geometry is multi-axis, the tool is long, or the material is hard, dry-run it and verify RTCP before cutting. The code is only as good as the setup behind it.

FAQs

Questions Engineers Ask About Gcode

Is Gcode the same on every CNC machine?

No. The core motion words such as G00, G01, and G02 are widely shared, but canned cycles, tool change syntax, and rotary axis naming differ between Fanuc, Siemens, Heidenhain, and Haas controls.

A program written for one control family may not run on another without a post-processor change. Always confirm the post matches the machine before the first cut.

Can I edit Gcode by hand after CAM output?

Yes, for small changes such as feed rate, clearance height, or a retract move. Hand editing is common when a tool needs a lower feed in a hard spot.

For geometry changes, go back to CAM. Manual edits to coordinates or arcs are hard to track and easy to get wrong.

What does RTCP do in a 5-axis program?

RTCP keeps the programmed point at the tool tip while the rotary axes tilt. Without it, the CAM system must calculate the offset, and small post errors grow with tool length.

On 5-axis centers, confirm RTCP is active before the first cutting move. If it is off, the surface will not match the model.

How long should a Gcode program be?

There is no right length. A simple pocket may need a few hundred blocks. A complex 5-axis surface can run to hundreds of thousands.

Program size matters for controller memory and transfer time, not for quality. Splitting a long program into tools or setups is normal practice.

Does Gcode control tolerance and surface finish?

It controls the path, not the result. Tolerance comes from the machine, the tool, the setup, and the inspection loop. Finish depends on feed, speed, tool condition, and control mode.

A clean program helps, but it cannot make a worn tool cut to ±0.005 mm or hold Ra 0.8 μm.

What happens if a program contains an error?

Most controllers stop at the block with a syntax error and show an alarm. Motion errors without an alarm are the dangerous ones, such as a wrong H offset or a missing G40.

That is why the first article is checked against the drawing, not against the simulation.

Send Us Your Model and We Will Handle the Code

Upload a STEP or IGES file and our engineers will review the geometry, choose the machine, and return a quote with DFM feedback within 12 hours.

12-hour quote100% inspectionNDA on request

Follow along

More from GreatLight

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