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

Get Instant Quote

Machining fundamentals

CNC G Code Explain: How a Part Actually Gets Cut

This page covers the command set behind every CNC program: motion codes, feed and speed words, offsets, and canned cycles. It is written for design engineers and buyers who read programs, review setups, or troubleshoot a part that came out wrong. By the end you can tell which lines drive the tool and which lines only set up the machine.

G0 to G3 motionFeed and speed wordsWork offsets G54Canned cycles
CNC G code basics explain on a machine control screen
The language

What CNC G Code Actually Describes

A CNC program is a list of instructions executed in order, one block per line. Each block tells the machine where to move, how fast to move, how fast to spin the tool, and which auxiliary action to take. The control reads the block, computes the path, and drives the servos. Nothing in the file is a suggestion. The machine does exactly what the numbers say, including the mistakes.

The letters in a block are called addresses. G addresses set the mode, such as rapid positioning or a feed move. X, Y and Z carry coordinates. F sets feed rate, S sets spindle speed, T selects a tool, and N is a line number that makes a program easier to restart. M codes handle the non-motion events: spindle on, coolant on, tool change, program end.

Most controls are modal. A G or F word stays active until another word of the same type replaces it. That is why a long finishing pass may carry only coordinates. The mode was set 40 lines earlier and never changed. Reading a program means tracking that state, not reading each line in isolation.

Programs come from CAM software, not from a person typing at the control. The CAM system takes a 3D model, applies toolpath strategy, and posts the result in the dialect of your machine. Fanuc, Siemens, Heidenhain and Haas all share the core G codes but differ in cycles and syntax. A post processor that is wrong by one decimal place will scrap the part.

  • 1
    G wordsSet the mode: motion type, plane, units, offsets.
  • 2
    Coordinate wordsX, Y, Z and rotary axes carry position.
  • 3
    F and SFeed rate and spindle speed, in mm/min and rpm.
  • 4
    M wordsSpindle, coolant, tool change, stop, end.
Motion

The Four Motion Codes That Do the Cutting

G0 is rapid positioning. The tool moves at the machine's maximum rate to a point where no material is being removed. It is a travel move, not a cutting move. Feed rate is ignored. On a 5-axis machine, a G0 that looks safe in three axes can swing the part into the fixture in the fourth. That is one reason setup simulation matters more than the code itself.

G1 is linear interpolation at a commanded feed rate. Two points, one straight line, material removed along the way. Almost all roughing and most finishing on flat or tapered surfaces is G1. Feed is set in mm/min on a mill and often in mm/rev on a lathe, so the same F value means different things on different machines. Always check the unit mode: G20 is inch, G21 is metric.

G2 and G3 are circular interpolation, clockwise and counterclockwise. They need an endpoint plus either a radius (R) or center offsets (I, J). A full circle cannot be cut as one arc on many controls, because the start and end point are identical and the control cannot resolve the plane. Programmers break it into two arcs or use a helical move.

Feed rate on an arc is the rate at the commanded path, not at the tool edge. On a small internal radius, the inside of the cutter travels much slower than the center, which raises chip load and can break a small end mill. Controls offer feed rate control on arcs for exactly this reason. For a Ø2 mm cutter in a tight corner, dropping the feed by 30 to 50 percent is normal practice.

  • 1
    G0Rapid travel, no cutting, maximum machine rate.
  • 2
    G1Straight cut at the programmed feed rate.
  • 3
    G2 / G3Clockwise and counterclockwise arcs.
  • 4
    G81 / G83Drilling and peck drilling cycles.
Offsets

Where the Tool Actually Is: Offsets and Compensation

A program is written against a coordinate system, not against a physical block of metal. Work offsets such as G54 through G59 tell the control where the part origin sits on the table. Change the fixture and you change the offset, not the program. This is what makes one file reusable across a batch of identical vises.

Tool length offsets tell the control how long each tool is. When a tool is replaced, the new length is measured and stored, and the program keeps running. Radius compensation, G41 for left and G42 for right, shifts the path sideways by the cutter radius so the programmer can draw the finished profile and let the control offset for the tool.

Compensation is the part engineers most often misread. A program with G41 does not cut on the line you see in the drawing. It cuts beside it. If the CAM post and the control both apply the offset, the part comes out undersized by roughly one tool diameter. That failure shows up as a slot that is too wide, not too narrow.

On our 5-axis centers, rotary axes add a second layer. The control blends linear and rotary motion, and the offsets must be correct in all five axes or the tool tip will not land where the CAM system expected. We verify the setup with a test cut or probing before the first production part is released.

  • 1
    G54–G59Work offsets: where the part sits on the table.
  • 2
    H and T wordsTool length and radius data stored in the control.
  • 3
    G41 / G42Cutter compensation, left and right of the path.
  • 4
    G43Applies tool length offset on a mill.
Boundaries

What G Code Cannot Fix, and When It Is the Wrong Tool

G code controls the path, not the physics. It cannot stop a long thin wall from deflecting, and it cannot remove heat from a cut. Chatter, taper and poor surface finish are usually rigidity, tooling or fixturing problems. Rewriting the program rarely solves them. If Ra is out of spec, check the setup before editing the code.

Feed and speed come from the material, the tool, and the depth of cut. Aluminium 6061 runs fast and dry or with light mist. Stainless 316 work hardens, so a dwell or a too-light pass will harden the surface and destroy the next tool. Titanium Ti-6Al-4V needs lower surface speed and more coolant. These are cutting-data decisions, not code decisions.

G code becomes the wrong tool when geometry is too complex to program by hand or when the part needs many setups. That is where 5-axis simultaneous machining and mill-turn work earn their place. A part with features on five faces, or one that needs turning and milling in the same setup, is a geometry problem first.

Our tolerance floor is ±0.005 mm (±0.0002 in), and surface finish runs from Ra 0.2–0.8 μm on a fine finish up to Ra 1.6–3.2 μm as machined. Hitting the tight end depends on the machine, the tool and the inspection plan together. The program is one input among several.

For prototypes and low-volume runs, no minimum order quantity applies. We can start production within 24 hours of a released order, and parts typically ship in 3–5 days. Quotation and a free DFM analysis come back within 12 hours.

Reference

Common G and M Codes at a Glance

Codes below are the ones that appear in almost every mill program. Lathe controls use a subset with different cycle syntax.

CodeWhat it doesTypical use
G0Rapid move, no cuttingMove between features
G1Linear cut at feed rateRoughing, flats, tapers
G2 / G3Arc, clockwise / counterclockwiseFillets, bosses, radii
G17 / G18 / G19Selects the working planeXY, XZ or YZ arcs
G20 / G21Inch or metric unitsCheck before every run
G41 / G42Cutter compensation left / rightProfile with tool radius
G43Tool length offset activeEvery tool change on a mill
G54First work offsetPart origin on the table
G81 / G83Drill / peck drill cycleHoles, deep holes
M3 / M4Spindle on, clockwise / counterBefore the first cut
M8 / M9Coolant on / offSteel, stainless, titanium
M30Program end and resetLast block of the file

Read the Program Before You Blame the Part

If the drawing is right and the part is wrong, check the setup, offsets and cutting data before you rewrite the code. Choose a shop that simulates and probes the setup when the geometry is complex; keep the code simple when it is not.

FAQs

Questions Engineers Ask About G Code

Do I need to read G code to get a good part machined?

No. You need a correct 3D model, a drawing with tolerances and finish callouts, and a note on which features are functional. The programmer handles the code.

Reading it helps when something goes wrong. If you can tell a rapid move from a feed move, you can usually follow a conversation about why a corner is chattering.

Why does the same F value behave differently on a mill and a lathe?

On a mill, feed is normally in mm/min, so the value is the table speed. On a lathe, feed is often in mm/rev, so the value is distance per spindle turn.

The unit mode also matters. G20 selects inch and G21 selects metric. A program posted in the wrong unit mode will run at the wrong scale, which is almost always a crash.

What is the difference between G41 and G42?

Both apply cutter radius compensation. G41 offsets to the left of the programmed path, G42 to the right.

Which one applies depends on the direction of travel and whether you are cutting an outside profile or an internal pocket. The control needs a lead-in move to engage the offset.

Can G code compensate for tool wear?

Yes, through the offset table. The operator adjusts the radius or length value for a worn tool and the program keeps running unchanged.

This is normal production practice. It is also why a shop that measures tools and logs offsets holds tolerance across a long run better than one that does not.

When should a part move to 5-axis machining instead of 3-axis?

When features sit on several faces, when a single setup is needed for datums, or when undercuts and contoured surfaces cannot be reached from three directions.

A 3-axis program stays simpler and cheaper to prove out. Moving to 5-axis adds setup complexity, so it should be driven by geometry, not by preference.

How do you keep a program confidential?

Uploads are handled as confidential, and an NDA is available on request before files are shared.

For defense-adjacent or medical work, we can restrict file access to the programming team assigned to the job.

Send the Model, Get a Quote and a DFM Review

Upload your CAD files and we will return a quotation with a free DFM analysis within 12 hours.

12-hour quote±0.005 mm tolerance100% inspection

Follow

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