Mastering CNC & VMC Programming
A comprehensive guide to CNC and VMC Programming — from machine axes and coordinate systems to G-code structure, cutting parameter calculations, canned cycles, toolpath strategies, and CAM-to-machine workflows. The complete reference for engineers, machinists, and programmers stepping from manual to precision computer-controlled machining.
What is CNC & VMC Machining?
CNC (Computer Numerical Control) is the automation of machine tools using a computer to execute pre-programmed sequences of machining commands. Rather than an operator manually cranking handles and setting dials, a CNC controller reads a program of coded instructions — primarily G-codes and M-codes — and precisely drives servo motors to move cutting tools along defined paths at controlled speeds and feeds, producing parts to micron-level accuracy and perfect repeatability.
A VMC (Vertical Machining Centre) is a CNC machine tool in which the spindle axis is oriented vertically — the cutting tool faces downward toward the workpiece. VMCs are the most widely used CNC machine type in precision manufacturing, capable of milling, drilling, boring, tapping, contouring, and pocketing operations. The worktable moves in the X (left-right) and Y (front-back) directions while the spindle moves in Z (up-down), with modern 4- and 5-axis VMCs adding rotational axes (A, B) for complex geometries in a single setup.
CNC programming is the language of precision manufacturing. A well-written program is not just code — it is the engineer's intent translated into movement, expressed with the accuracy that human hands alone could never achieve. — Precision Engineering Principle
Machine Axes & Coordinate Systems
Every CNC program is written in a coordinate system. Understanding the three primary linear axes and the two rotational axes — and how they relate to the machine, the workpiece, and the program origin — is the absolute foundation of all CNC programming.
Left and right movement of the worktable or spindle. Positive X moves the table to the right (or tool to the right relative to the workpiece). Primary axis for facing and contouring operations.
Front-to-back movement. Positive Y moves the table toward the operator (or away from the spindle). Combined with X for 2D contouring in the XY plane — the primary machining plane for VMC.
Up and down movement of the spindle. Positive Z moves the tool away from the workpiece (retract); negative Z plunges into the material. Depth of cut is controlled entirely in Z.
Rotational axis around the X-axis — used in 4th and 5th axis VMC machining. Enables complex helical features, angled surfaces, and multi-face machining in a single setup without repositioning.
Rotational axis around the Y-axis — the 5th axis on advanced VMC centres. Enables fully simultaneous 5-axis machining for aerospace turbine blades, impellers, and complex sculptured surfaces.
Fixed reference point of the machine itself — set at the machine home position. The controller always knows its position relative to the MCS. Used for machine limits, tool changes, and home position moves.
The programmer-defined origin for the workpiece — typically set at a corner, the centre of the part, or a datum feature. All program coordinates are relative to this point. Set using G54–G59 work offset registers.
G90 Absolute: All positions measured from the program zero point (WCS). G91 Incremental: Each position is relative to the current tool position. Most programs use G90 as default — safer and easier to verify against the drawing.
G-Code Program Structure
A CNC program is a sequence of blocks (lines of code), each containing one or more words (a letter address followed by a numerical value). The program opens with a program number, sets up the machining environment (units, plane, mode), calls tools and sets cutting conditions, executes cutting moves, and ends with a safe return to home. Understanding this structure is essential before writing a single line.
Every program block follows the same word-address format: a letter (the address) followed by a number (the value). The controller reads each block sequentially — or in modal fashion, where codes like G90, G21, and G01 remain active until overridden. Understanding which codes are modal (persistent) and which are non-modal (one-shot) is fundamental to writing clean, predictable programs.
Essential G-Codes Reference
G-codes (Preparatory codes) define the type of motion or mode the machine should execute. They are the core vocabulary of CNC programming. Most G-codes are modal — once activated, they stay in effect until replaced by another code in the same group.
Move to position at maximum machine speed — not cutting, no feedrate control. Used for repositioning, approach, and retract moves.
Straight-line cutting move at programmed feedrate (F). The most fundamental cutting move — facing, pocketing, contouring, and chamfering.
Clockwise arc move at the programmed feedrate. Defined by endpoint (X, Y), arc radius (R) or centre offset (I, J). For internal radii and CW contours.
Counter-clockwise arc move. For external radii, rounded corners, and CCW contour profiles. Paired with G02 for complete circular pockets.
Select the XY plane for circular interpolation and canned cycles. Default and most common plane for VMC operations — essential at program start.
G20 activates imperial (inch) mode; G21 activates metric (mm) mode. Must be set at program start and match the toolpath units from CAM software.
Return to the machine reference position via an intermediate point. Used at program end and before tool changes. Always call G28 Z0 first before X and Y.
Cancels G41/G42 cutter compensation. Must be called when leaving the workpiece boundary to avoid gouging. Part of the safe program header.
Offsets the tool path left (G41) or right (G42) by the tool radius stored in the D register — enabling the program to be written to the part profile, not the tool centre.
Applies the tool length offset value stored in the H register to compensate for the actual tool length vs. the programmed Z datum. Essential for every tool call.
Six programmable work coordinate systems. G54 is the most common (first workpiece). G55–G59 allow multiple fixtures or operations in one program setup.
G90: all coordinates measured from program zero (absolute). G91: each coordinate measured from the current tool position (incremental). G90 is the standard default.
G94: feedrate in mm/min (most common for milling). G95: feedrate in mm/rev (used for turning and some drilling operations). Must match your speeds and feeds calculation.
G96: constant surface speed (CSS) — spindle speed adjusts with diameter. G97: constant RPM mode. VMC milling typically uses G97 constant RPM.
M-Codes — Miscellaneous Functions
M-codes (Miscellaneous codes) control the machine functions that are not motion-related — spindle start/stop, coolant on/off, tool changes, pallet changes, and program control. Unlike G-codes, most M-codes are non-modal (they execute once and stop). Only one M-code can typically appear per block.
| M-Code | Function | Detail | Type |
|---|---|---|---|
M00 | Program Stop | Stops all motion, spindle, and coolant. Operator must press Cycle Start to resume. Used for mid-program inspection or part flipping. | Non-Modal |
M01 | Optional Stop | Same as M00 but only activates when the Optional Stop switch on the control panel is ON. Used for quality checks during production without stopping every cycle. | Non-Modal |
M02 | Program End | Signals end of program. Stops all axes and auxiliary functions. Does not rewind the program — use M30 for end-and-rewind in production. | Non-Modal |
M03 | Spindle ON — CW | Starts spindle clockwise at the S-word speed. Standard for right-hand cutting tools. Always preceded by S (speed) word in the same or previous block. | Modal |
M04 | Spindle ON — CCW | Counter-clockwise spindle rotation — used for left-hand taps, reverse helical milling, and special operations. Rare in standard VMC work. | Modal |
M05 | Spindle STOP | Stops the spindle with controlled deceleration. Always call M05 before a tool change and before program end. M06 implies M05 on most controls. | Non-Modal |
M06 | Tool Change | Commands the ATC (Automatic Tool Changer) to change to the tool number specified by the preceding T-word. Machine first moves to tool change position (G28). | Non-Modal |
M08 | Coolant ON | Activates flood coolant. Turn on coolant immediately after positioning for cutting — before the first cutting move. Essential for tool life and surface finish. | Modal |
M09 | Coolant OFF | Stops all coolant flow. Call before G28 return to home to avoid coolant spray during rapid machine motion across the work envelope. | Non-Modal |
M19 | Spindle Orient | Orients the spindle to a fixed angular position for tool change. Called automatically by M06 on most VMC controllers — rarely needed in the program. | Non-Modal |
M30 | Program End & Rewind | Ends program execution, resets all modal codes, and rewinds the program to the beginning for the next cycle. The correct ending code for all production programs. | Non-Modal |
M98 | Subprogram Call | Calls a subprogram (subroutine) identified by the P-word address. Enables reuse of repeat geometry patterns — bolt hole circles, repeated pockets — without rewriting code. | Non-Modal |
M99 | Subprogram Return | Returns execution from a subprogram back to the main program at the block following the M98 call. Essential for subprogram structure. | Non-Modal |
Canned Cycles — Automated Hole Operations
Canned cycles (G73–G89) are pre-programmed subroutines stored in the CNC controller that automate repetitive hole-making operations — drilling, tapping, boring, and reaming. Instead of writing multiple blocks for each drill depth and retract, a single canned cycle block defines the entire operation. The cycle then repeats at every XY coordinate specified in subsequent blocks until G80 cancels it.
| Code | Cycle Name | Operation | Key Parameters |
|---|---|---|---|
G73 | High-Speed Peck Drilling | Rapid pecking with partial retract for chip breaking. Faster than G83 — no full retract between pecks. Ideal for short-chipping materials. | Z, R, Q, F |
G74 | Left-Hand Tapping | Reverse (CCW) tapping cycle for left-hand threads. Spindle reverses automatically at depth for extraction. Uses spindle-synchronised feedrate. | Z, R, F (= pitch × RPM) |
G76 | Fine Boring Cycle | Precision boring with tool shift at hole bottom before retract — prevents drag marks. For tight-tolerance bores requiring fine surface finish. | Z, R, Q (shift), F |
G80 | Cancel Canned Cycle | Cancels any active canned cycle. Must be programmed after the last hole operation. Failure to cancel causes the cycle to execute at subsequent XY moves. | — |
G81 | Standard Drilling | Simple drill cycle — rapid approach to R-plane, feed to depth Z, rapid retract. Ideal for through-holes and shallow holes where chip evacuation is not critical. | Z, R, F |
G82 | Spot Drilling / Counterbore | Drill cycle with dwell at hole bottom (P-word milliseconds). Used for spot drilling, countersinking, and counterboring where a flat bottom and accurate entry are required. | Z, R, P, F |
G83 | Full Retract Peck Drilling | Deep hole drilling — full retract to R-plane between each Q-depth peck. Clears chips completely and allows coolant to reach the cutting edge in deep holes. | Z, R, Q, F |
G84 | Right-Hand Tapping | Standard tapping cycle — spindle CW on entry, reverses (CCW) at depth for retract. Feedrate must equal thread pitch × RPM. Rigid tapping (G84.2 on some controllers) provides superior accuracy. | Z, R, F |
G85 | Boring (Feed In / Feed Out) | Boring cycle feeding both in and out — good surface finish but slower. The retract feedrate is the same as the cutting feedrate, preventing drag marks in soft materials. | Z, R, F |
G86 | Boring (Feed In / Rapid Out) | Boring cycle with rapid retract — faster than G85 but can leave drag marks on the bore surface if the spindle is not oriented before retract. Use G76 for precision bores. | Z, R, F |
Cutting Parameters — Speeds, Feeds & Depths
Correct cutting parameters are the difference between a tool that machines efficiently for hours and one that breaks on the first pass. Speeds and feeds are not guesses — they are calculated from the tool diameter, workpiece material, and cutting tool material using well-established formulae and manufacturer data.
Vc = Cutting speed (m/min) from tool data
D = Tool diameter (mm)
Example: Vc=120, D=12mm → N = 3,183 RPM
fz = Feed per tooth (mm) from tool data
Z = Number of cutting flutes
N = Spindle speed (RPM)
ap = Axial depth of cut (mm)
ae = Radial depth of cut (mm)
Vf = Feed rate (mm/min)
fn = Feed per revolution (mm/rev) from drill data
N = Spindle speed (RPM)
Typical fn for steel: 0.05–0.25 mm/rev
Surface speed at the cutting edge — determined by the workpiece material and tool coating. Steel: 80–150 m/min for coated carbide. Aluminium: 200–600 m/min. The starting point for all calculations.
RPM programmed in the S-word. Always calculated from Vc and tool diameter — never guessed. Smaller tools require proportionally higher RPM to achieve the same surface speed.
Chip load per flute — the fundamental feed parameter. Too low: rubbing, work-hardening, poor tool life. Too high: chatter, breakage. Typical 4-flute 12mm end mill in steel: 0.03–0.06 mm/tooth.
How deep the tool cuts in Z — the engagement length of the flutes. Roughing: up to 1.5× D for short tools. Finishing: 0.2–0.5mm. Reduces with increased radial engagement and harder materials.
Stepover in the XY plane — the width of each cutting pass. Roughing: 50–75% of tool diameter. High-speed machining: 5–15% D with high feed rates. Directly impacts surface finish and tool load.
Programmed as the F-word in G01/G02/G03 blocks. Calculated from fz × flutes × RPM. Separate feedrates for approach, cutting, and finishing passes improve quality and tool life.
| Material | Cutting Speed Vc (m/min) | Feed/Tooth fz (mm) | Coolant | Notes |
|---|---|---|---|---|
| Mild Steel (EN8) | 80–120 | 0.04–0.07 | Flood | Standard coated carbide, 4-flute end mill |
| Stainless (316) | 50–80 | 0.02–0.05 | Flood | Reduce speed, increase feed — avoid work hardening |
| Alloy Steel (EN36) | 60–100 | 0.03–0.06 | Flood | Higher hardness — use TiAlN coated tools |
| Cast Iron | 100–180 | 0.04–0.08 | Dry / Air | No coolant — graphite swarf + coolant = abrasive paste |
| Aluminium (6061) | 250–500 | 0.05–0.15 | Mist | 3-flute polished flute tools — high helix, sharp edge |
| Titanium (Ti6Al4V) | 30–60 | 0.02–0.04 | High-Press. | Low speed, low ap, sharp tools — heat management critical |
| Hardened Steel (>50 HRC) | 40–80 | 0.01–0.03 | Near-Dry | CBN or ceramic inserts; very light depths of cut |
Tool Offsets & Work Offsets
Offsets are the bridge between the idealized geometry in a CNC program and the physical reality of the machine, the tooling, and the workpiece. Correctly setting and verifying offsets before the first cut is one of the most critical skills a CNC operator and programmer must master.
Every tool has a different physical length. The Tool Length Offset (TLO) stores the difference between the actual tool tip position and the programmed Z datum when the spindle is at the reference position. Set using a tool pre-setter, Z-axis probe, or manual tool touch-off at the work surface. Called in the program with G43 Hxx — where xx matches the tool number. Without G43, the program's Z coordinates are meaningless.
The Work Offset tells the controller where the program zero (X0, Y0, Z0 in the program) is physically located in the machine coordinate system. Typically set with a Renishaw work probe (edge finder or 3D probe) or manual DTI and edge finder combination. The measured offset values are stored in the G54–G59 registers via the controller offset screen. A single mistyped digit in the work offset causes a crash or an incorrect part.
When a program is written to the part profile (not the tool centre path), G41/G42 offsets the tool centre left or right by the radius stored in the D register. This allows the same program to be used with slightly different tool diameters or to apply a finishing stock removal by adjusting the D value — without changing the program. G41 = left of direction of travel (typically used for external profiles); G42 = right (internal profiles).
CAM Programming — Computer-Aided Manufacturing
For complex parts, freeform surfaces, and 4/5-axis operations, CAM (Computer-Aided Manufacturing) software generates G-code automatically from a 3D CAD model. The programmer defines strategies, tools, and parameters; the CAM system computes the toolpath and post-processes it into machine-specific G-code. CAM does not eliminate the need for programming knowledge — understanding G-code is essential to verify, edit, and troubleshoot CAM output.
Mastercam — most widely used in job shops; Fusion 360 — cloud-based, popular for prototype and SME work; NX CAM — aerospace and automotive tier-1; CATIA — complex surface machining; SolidCAM — SolidWorks-integrated; EdgeCAM — turning and milling.
Facing — clear flat surfaces; Contour — follow profile; Pocket — clear enclosed areas; Adaptive (HSM) — constant chip load high-speed milling; Drilling — hole operations; 3D surface — scallop, parallel passes; 5-axis swarf — ruled surface with side of tool.
The post-processor converts the generic CAM toolpath into the specific G-code dialect of the target machine controller — Fanuc, Siemens 840D, Heidenhain, Mitsubishi. A correctly configured post is critical — wrong posts produce syntax errors, incorrect canned cycles, or unsafe tool changes. Each machine requires its own verified post-processor file.
Before running any new program on the machine, simulate with tools such as Vericut, NCSimul, or the CAM system's built-in simulator. Simulation detects tool-holder collisions, rapid moves through material, incorrect offsets, and gouges — preventing expensive crashes and scrapped parts. Non-negotiable for any complex, long-cycle, or expensive workpiece.
Program Structure, Safety & Best Practices
A correct CNC program is not just one that produces the right geometry — it is one that is safe, readable, maintainable, and robust. Following a consistent program structure prevents crashes, protects expensive tooling and workpieces, and makes programs easy to troubleshoot and hand over to other operators.
Every program must open with a block that cancels all potentially dangerous modal states: G21 G17 G40 G49 G80 G90 G94. This line cancels cutter compensation (G40), tool length compensation (G49), canned cycles (G80), and sets metric mode, XY plane, absolute positioning, and feed per minute. Starting without this block means the machine inherits whatever modal state was left by the previous program — a known cause of crashes.
G21 G17 G40 G49 G80 G90 G94 — include in every program, every time.At the end of any program or before a tool change, always retract Z to safe height (or machine home) before moving X and Y. Moving XY while the tool is still at machining depth drags the tool across the workpiece surface — damaging both. The correct sequence is always: G91 G28 Z0 (Z home), then G28 X0 Y0.
For every new or modified program, run the first cycle with Single Block mode active and feedrate override at 10–25%. Step through each block individually, verifying each tool position before allowing motion. Only once the program has completed a full first article inspection and been approved should it be run in automatic mode at full feed. Never run an unverified program in auto mode — the cost of a crash always exceeds the time saved.
Add parenthetical comments after every tool call, operation change, and non-obvious move: (TOOL 1 - 50MM FACE MILL), (ROUGHING POCKET - DEPTH 10MM). Use a consistent program numbering and naming convention — program number, part number, revision, and date in the header comment. A program that can be read and understood quickly is a program that can be safely modified and corrected under pressure.
Before the first cut on an expensive workpiece, add +50mm to the G54 Z offset to run the entire program in the air above the part. Verify all rapid positions, tool changes, approach moves, and cycle patterns are correct visually before reducing the offset back to zero and cutting material. This air cut is the single most effective crash-prevention technique available to the operator.
Applications & Benefits
CNC and VMC machining is the backbone of precision manufacturing worldwide — from single prototype parts to millions of identical components. Its precision, repeatability, and programmability make it indispensable across virtually every engineering industry.
5-axis VMC machining of titanium structural components, aluminium bulkheads, and complex engine parts to tolerances of ±0.005mm. CAM-driven toolpaths for turbine blades, impellers, and landing gear components where a single defect can be catastrophic.
High-volume VMC machining of engine blocks, cylinder heads, transmission housings, and brake components. Transfer lines with multiple VMCs and pallet changers producing hundreds of identical parts per shift with automated quality gauging.
Precision machining of surgical implants, prosthetics, and instrument components in titanium, cobalt-chrome, and PEEK. Sub-micron tolerances and exceptional surface finish for biocompatibility — with full traceability documentation for regulatory compliance.
Hardened steel mould cavities, EDM electrodes, and press tools machined with high-speed VMC techniques — fine stepover scallop passes in hardened steel at 60+ HRC to achieve Ra 0.4µm surface finish without polishing, reducing lead time significantly.
- Micron-level precision and part-to-part repeatability impossible by hand
- Complex 3D geometries achievable in a single setup with 5-axis VMC
- Dramatic reduction in skilled operator time per part
- 24/7 unmanned production with pallet changers and robot loading
- Rapid changeover between parts — reprogramming takes minutes, not days
- Complete traceability — program version controls every cut made
- CAM integration eliminates manual calculation errors
- Consistent surface finish and dimensional accuracy regardless of operator
- Work offset and tool offset errors are the #1 cause of VMC crashes
- Tapping feedrate miscalculation destroys taps and damages workpieces
- Forgetting G80 leaves an active canned cycle — drills unexpected positions
- Wrong post-processor output causes syntax errors or unsafe machine behaviour
- Insufficient fixture clamping causes chatter, poor finish, and dangerous part release
- Rapid moves through material — forgetting G00 vs G01 at depth
- Cutter radius compensation activated/cancelled incorrectly causes gouges
Key Takeaway
CNC and VMC programming is both a science and a craft. The science is precise: speeds and feeds follow mathematics, G-code follows standards, and coordinates follow geometry. The craft is experiential: knowing how a specific material reacts to tooling, recognising the sound of correct chip formation, understanding how the machine behaves at the limits of its rigidity, and building the disciplined habits — safe headers, single-block prove-outs, air cuts, and comment-rich programs — that separate an exceptional programmer from a dangerous one.
Whether you are writing your first facing program or programming a 5-axis impeller in Fusion 360, the fundamentals never change: understand your coordinate system, calculate your cutting parameters from data not intuition, prove out every new program before cutting, and treat every rapid move as a potential crash waiting to happen. The machine will do exactly what you tell it — with ruthless, unforgiving precision.
A CNC machine does not know the difference between the workpiece and the fixture, the tool and the tombstone, or a good program and a bad one. It executes instructions. Every crash, every scrapped part, and every broken tool began with a human decision — a wrong number, a missing block, a skipped verification step. Master the safe habits first, master the code second, and master the material science third. In that order, every time.


nice to see this informative page about cnc programming.