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

Get Instant Quote

Explainer

CNC Machining Center Code List: How the Codes Actually Work

A working guide for engineers and programmers who need to read a CNC machining center code list and know what each line does to the machine. It covers G codes, M codes, tool and offset codes, and the boundary conditions that decide whether a program runs clean or scraps the part.

G codesM codesTool offsetsCanned cycles
CNC machining center code list reference for G codes and M codes
How codes divide the work

What a CNC machining center code list really controls

Every block in a CNC program is a short command that changes machine state. Some lines move an axis. Some lines turn a spindle on or off. Some lines tell the controller which tool is in the spindle and how far that tool sits from the gauge line. The CNC machining center code list is simply the vocabulary the controller understands when it reads those lines.

On a typical vertical machining center, G codes handle motion and geometry. M codes handle machine functions such as spindle rotation, coolant, and tool changes. T codes select the tool, H codes call the length offset, and D codes call the cutter radius offset. Feed and speed are written with F and S. Once you see those five groups, a long program stops looking like noise.

The same letter can mean different things on different builders. On many Fanuc-based controls, G54 through G59 select work coordinate systems. On a Siemens control, the syntax for the same idea looks different. The list below follows the common ISO/Fanuc convention because it is the base dialect for most vertical and horizontal machining centers.

Codes do not cut metal. They describe intent. The machine still has to convert that intent into servo motion, spindle torque, and coolant flow. That is why two programs with the same G codes can produce different surface finishes and different tool life. The code is the plan; the machine, the tool, and the material decide the result.

  • 1
    G codesMotion type, plane selection, offsets, and canned cycles.
  • 2
    M codesSpindle, coolant, tool change, and program stop functions.
  • 3
    T, H, D codesTool number, length offset, and cutter radius offset.
  • 4
    F and SFeed rate in mm/min or in/min, and spindle speed in rpm.
Motion group

G codes: the motion half of the CNC machining center code list

G00 is rapid positioning. The machine moves at the fastest safe rate to a point, usually above the part or at a clearance plane. G01 is linear interpolation at a programmed feed. If you command G01 F250, the tool moves in a straight line at 250 mm/min along the vector you defined with X, Y, and Z.

G02 and G03 are circular interpolation, clockwise and counterclockwise. They need an arc endpoint plus either a radius with R or a center with I, J, and K. The R form is shorter and easier to read. The I, J, K form is more reliable for arcs over 180 degrees and for full circles, where the R form can produce a wrong center on some controls.

G17, G18, and G19 choose the working plane: XY, XZ, and YZ. Most 3-axis milling runs in G17. On a 5-axis machine, the plane selection interacts with the rotary axes and the postprocessor output, so it deserves a check before the first cut. G20 and G21 set the units to inches or millimeters. Mixing them is one of the fastest ways to send a tool through a vise.

G28 sends the machine to its reference position, usually through an intermediate point. G43 applies tool length compensation with an H number. G54 to G59 select the work offset. G73 and G83 are peck drilling cycles. G81 is a simple drill cycle. G84 is rigid tapping. G40 cancels cutter compensation, G41 is left compensation, and G42 is right compensation. G90 and G91 switch between absolute and incremental positioning. G98 and G99 set the return plane for canned cycles.

  • 1
    G00 / G01Rapid move and linear feed move.
  • 2
    G02 / G03Clockwise and counterclockwise arc moves.
  • 3
    G43 / G49Apply and cancel tool length compensation.
  • 4
    G54–G59Work coordinate systems for different fixtures.
Machine function group

M codes: spindle, coolant, and the machine's housekeeping

M03 starts the spindle clockwise. M04 starts it counterclockwise. M05 stops it. M08 turns coolant on and M09 turns it off. M06 performs a tool change, usually after the spindle stops and the machine moves to the tool change position. These are the lines you will see in nearly every program.

M00 is a program stop that waits for the operator to press cycle start. Use it for a manual chip clear, a part flip, or a probe check. M01 is an optional stop that only pauses when the operator has the optional stop switch enabled. M30 ends the program and rewinds it to the top. M02 ends the program without the rewind on older controls.

On machines with through-spindle coolant, M07 or a builder-specific M code selects it. High-pressure coolant is often M08 with a pump command, or a separate M code that enables the high-pressure circuit. Always check the machine manual, because this group is where builders diverge most.

M codes do not always move the axes. That matters when you write a stop for a manual operation. If the tool is still inside the part and you issue M00 without a retract, the operator has to jog the machine by hand. Put a G00 Z clearance move before any manual stop.

  • 1
    M03 / M04 / M05Spindle forward, reverse, and stop.
  • 2
    M06Tool change command.
  • 3
    M08 / M09Coolant on and off.
  • 4
    M00 / M01 / M30Program stop, optional stop, and end of program.
Offsets and geometry

T, H, and D codes: where accuracy is won or lost

The T code tells the controller which pocket to pull from. The H code tells it how long that tool is compared with the gauge line. The D code tells it how wide the cutter is compared with nominal. Get any of these wrong and the machine will cut air, cut too deep, or leave a wall that is out of tolerance.

Tool length offsets are usually set with a presetter or a touch-off on the machine. A 0.02 mm error in the length offset shows up directly in the Z depth of every feature that tool cuts. On a part with a ±0.005 mm tolerance, that error is already four times the tolerance band. Offsets are not paperwork. They are part geometry.

Cutter radius compensation lets you program the part profile and let the control offset the path by the tool radius. G41 and G42 handle that. The advantage is that a reground tool or a slightly different cutter diameter does not force a program rewrite. You update the D value and run the same path. The trade-off is that the control now has to solve the offset geometry, and tight inside corners can alarm out or leave a witness mark if the radius is too large.

A worn 12 mm end mill may measure 11.94 mm. If you run it without compensation, every slot it cuts is 0.06 mm narrow. If you run it with G41 and a D value of 11.94, the slot comes back to 12.00 mm on the control side. That is the whole point of the D code.

  • 1
    T01–T99Tool pocket selection.
  • 2
    H01–H99Length offset for each tool.
  • 3
    D01–D99Cutter radius offset for compensation.
  • 4
    G41 / G42 / G40Left compensation, right compensation, and cancel.
Cycles and subprograms

Canned cycles, subprograms, and macro variables

Canned cycles pack a repeated motion into one line. G81 drills a hole with a feed to depth and a rapid retract. G83 pecks to clear chips, which matters in deep holes and gummy materials such as 6061 aluminum or 304 stainless. G73 is a high-speed peck cycle for shallower holes. G84 taps a hole with a synchronized spindle and feed.

A canned cycle stays active until you cancel it with G80. That is a common trap. If you drill a pattern with G81 and then write a G01 move without G80, the control may treat the move as another drilling position. The tool plunges where you wanted a straight line. Always cancel the cycle before a new motion type.

Subprograms use M98 to call and M99 to return. They are useful for repeated features such as a bolt pattern or a family of identical pockets. Macro variables push this further. A macro can calculate a toolpath from a few inputs, which is how many shops handle families of parts without writing a program per size.

Macros are powerful and easy to break. A wrong variable can change a feed rate or a depth across the whole program. Keep macro logic simple, document the input variables, and dry-run the first article with the tool clear of the stock.

  • 1
    G81 / G83Simple drilling and peck drilling.
  • 2
    G84Rigid tapping cycle.
  • 3
    G80Cancel canned cycle. Always use it.
  • 4
    M98 / M99Call and return from a subprogram.
Practical limits

Where the code list stops and the machine takes over

A code list describes commands, not capability. A G01 move is legal on any machine. Whether the machine can hold ±0.005 mm at that feed rate depends on the machine's rigidity, the tool, the fixturing, and the thermal state of the shop. A well-written program on a worn machine will still produce worn parts.

Feed and speed are the two values that decide tool life. In 6061 aluminum, a 12 mm carbide end mill might run at 3,000 to 6,000 rpm with a feed of 1,000 to 2,500 mm/min, depending on radial and axial engagement. In 304 stainless, spindle speed drops and feed per tooth drops with it. The code list gives you F and S. It does not tell you the numbers.

Cutting data also depends on the toolpath strategy. A trochoidal path keeps radial engagement low, which lets you run a higher feed and longer tool life in hard materials. A conventional slotting pass buries the full cutter width in the material and generates more heat. Same G codes, very different outcome.

The boundary is simple. Codes control position and sequence. They do not control chatter, deflection, or heat. When a part goes out of tolerance, check the offsets and the program first, then check the setup and the tool. Most tolerance problems live in the second group.

  • 1
    Offset errorShows up as a constant shift on every part.
  • 2
    DeflectionShows up as taper or a size change with depth.
  • 3
    Thermal growthShows up as a slow drift across the run.
  • 4
    Tool wearShows up as a gradual size change over many parts.
Reference table

Common CNC machining center code list entries and their engineering effect

Use this as a quick cross-check when reading a program or writing a postprocessor.

CodeFunctionEngineering effect
G00Rapid positioningFast move, no cutting. Keep clear of stock.
G01Linear feed moveFeed rate F sets chip load and surface finish.
G02 / G03Arc interpolationR form is short; I, J, K is safer over 180°.
G17 / G18 / G19Plane selectionWrong plane breaks arcs and canned cycles.
G20 / G21Inch or metric unitsA mismatch can scrap the part in the first move.
G43 / G49Length compensation on / offH offset error shifts every Z depth.
G54–G59Work coordinate systemsLets one program run on several fixtures.
G81 / G83 / G84Drill, peck drill, tap cyclesG83 clears chips in deep holes and gummy alloys.
G41 / G42 / G40Cutter compensation left / right / offD value absorbs tool wear and regrinds.
M03 / M05Spindle on / offSpindle ramp needs a dwell before the first cut.
M06Tool changeWrong T number means wrong tool and wrong offset.
M08 / M09Coolant on / offCoolant choice affects chip evacuation and finish.

When to use the code list, and when to stop reading it

Use the code list to read and verify a program, and to catch unit, plane, and offset mistakes before the first cut. Stop using it as a source of cutting data. If you need ±0.005 mm and Ra 0.8–1.6 μm on a real part, the decision belongs to the tool, the fixture, and the machine, not to a list of G codes.

FAQs

Questions engineers ask about CNC machining center codes

Is the G code list the same on every CNC machining center?

No. The common ISO and Fanuc-style set is widely shared, but builders add, remove, or rename codes. M codes for through-spindle coolant are a good example. The basic motion codes behave the same on most machines, which is why the list is still useful as a starting point.

Always check the machine manual before running an unfamiliar code. A code that is harmless on one control can be an alarm or an unexpected move on another.

What is the difference between G41 and G42?

G41 offsets the tool to the left of the programmed path, G42 to the right. The correct choice depends on the direction of travel and whether you are climb milling or conventional milling.

G40 cancels compensation. If you leave compensation active and start a new feature, the control may offset a path you wanted on the line.

Why does my drilling cycle keep drilling after I cancel it?

You probably did not cancel it. A canned cycle stays active until G80 is issued. Any XY move after a G81 or G83 is treated as another hole position.

Put G80 immediately after the last hole and before any contour or positioning move. This is one of the most common program errors in hand-written code.

How often should tool length offsets be checked?

Check them at the start of every job and after every tool change that involves a new or reground tool. A 0.02 mm offset error is already four times a ±0.005 mm tolerance.

On long runs, re-check the offsets at set intervals. Thermal growth in the spindle and the ballscrews can shift the effective length over a few hours.

Can I use the code list to estimate machining time?

Only roughly. You can add up the feed moves and divide by the feed rate, but that ignores rapids, tool changes, acceleration, and any dwell. On a part with many short moves, the real cycle time can be much longer than the simple estimate.

For a firm number, run the program on the machine or use the CAM software's time estimate with the real machine acceleration values.

Do 5-axis machines use a different code list?

The same core codes are used, plus rotary axis commands and sometimes machine-specific functions for tool center point control. The postprocessor handles most of that conversion.

The risk on 5-axis work is not the code list, it is the setup. A wrong work offset on a rotary table can rotate the part into the tool. Verify the setup and dry-run with the tool clear of the stock.

Send us the drawing, not just the code

Upload a STEP file and we will return a quotation and a free DFM analysis within 12 hours. No minimum order quantity, from one prototype to 10,000+ part runs.

12-hour quote100% inspectionNDA on request

Follow

More machining notes 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