CNC Programming Guide — G-Code, CAM Setup, Toolpaths & Machining Strategies
CNC (Computer Numerical Control) programming is the language that drives precision machining. Whether you are creating simple 2D profiles or complex 5-axis freeform surfaces, understanding programming fundamentals is essential for achieving accurate, efficient, and repeatable machining results.
This guide covers G-code basics, CAM programming workflow, toolpath strategies, and material-specific considerations for CNC machining.
G-Code Fundamentals
G-code is the standard programming language for CNC machines. Despite differences between machine controllers (Fanuc, Siemens, Heidenhain, Haas), the core G-code commands are universal.
Essential G-Codes
| Code |
Function |
Example |
| G00 |
Rapid positioning (fast move, no cutting) |
G00 X100 Y50 Z10 |
| G01 |
Linear feed (cutting move) |
G01 X100 Y50 F200 |
| G02 |
Circular interpolation clockwise |
G02 X50 Y50 R25 |
| G03 |
Circular interpolation counterclockwise |
G03 X50 Y50 R25 |
| G17/G18/G19 |
Work plane selection (XY/ZX/YZ) |
G17 (default XY plane) |
| G20/G21 |
Units (inches/mm) |
G21 (metric mode) |
| G40/G41/G42 |
Cutter compensation off/left/right |
G41 D1 (comp left) |
| G43 |
Tool length compensation positive |
G43 H1 |
| G54-G59 |
Work coordinate system offsets |
G54 |
| G90/G91 |
Absolute/incremental positioning |
G90 |
Essential M-Codes
| Code |
Function |
| M03 |
Spindle on (clockwise) |
| M04 |
Spindle on (counterclockwise) |
| M05 |
Spindle stop |
| M06 |
Tool change |
| M08 |
Coolant on |
| M09 |
Coolant off |
| M30 |
Program end and rewind |
CAM Programming Workflow
Modern CNC programming is done through CAM (Computer-Aided Manufacturing) software. The typical workflow:
- Import CAD model — STEP, IGES, or native CAD format
- Define stock material — Set raw material dimensions and reference point
- Machine definition — Select the machine model, tool changer, and limits
- Tool selection — Choose appropriate tools from the tool library
- Create operations — Define roughing, finishing, drilling, and other operations
- Simulate — Run virtual simulation to check for collisions and verify results
- Post-process — Generate machine-specific G-code through a post-processor
- Transfer and run — Send the program to the machine via DNC or USB
Toolpath Strategies by Application
2D Machining
Used for simple profiles, pockets, holes, and slots. Common strategies:
- Contour/profiling — Cutting along a 2D outline. Used for final part profiles
- Pocketing — Clearing material from enclosed areas. Can be zigzag, spiral, or morph spiral
- Drilling — Standard drill cycles (G81 for spot, G73 for peck, G83 for deep hole)
- Slot milling — Cutting slots with end mills, typically using trochoidal or plunge strategies
3D Surface Machining
Used for complex freeform surfaces like molds, dies, and aerospace components:
- Parallel finishing — Cuts along parallel planes. Simple but may leave scallop marks on steep areas
- Contour finishing — Cuts along Z-level contours. Good for vertical walls and steep surfaces
- Scallop finishing — Maintains constant stepover distance for uniform surface finish
- Pencil tracing — Follows fillets and concave intersections to clean corners
- Rest machining — Removes material left by a previous larger tool (used for corner cleaning)
5-Axis Machining
5-axis CNC machines add two rotary axes (A/B or B/C) to the standard X/Y/Z, enabling complex geometries in fewer setups:
- 3+2 machining — The rotary axes position the part, then 3-axis machining is performed. Used for angled holes and undercuts
- Full 5-axis simultaneous — All five axes move simultaneously. Used for complex impellers, turbine blades, and medical implants
- 5-axis swarf cutting — The side of the tool contacts the surface. Ideal for ruled surfaces like airfoils
| Strategy |
Best for |
Cycle time |
Surface finish |
| 3+2 positioning |
Complex holes, undercuts |
Fast (fewer setups) |
Good |
| 5-axis continuous |
Turbine blades, impellers |
Moderate |
Excellent |
| Swarf cutting |
Ruled surfaces |
Fast |
Excellent |
Material-Specific Machining Strategies
Aluminum (6061, 7075, 2024)
- High spindle speeds (8,000-15,000 RPM recommended)
- High feed rates (0.1-0.3 mm/tooth)
- Use sharp carbide tools with polished flutes to prevent built-up edge
- Flood coolant or MQL (minimum quantity lubrication) preferred
- Trochoidal milling paths reduce tool engagement and allow deeper cuts
Steel (Mild, Tool, Stainless)
- Lower spindle speeds (2,000-6,000 RPM for HSS; 4,000-10,000 for carbide)
- Moderate feed rates (0.05-0.15 mm/tooth)
- Use TiAlN or AlTiN coated carbide for heat resistance
- Stainless requires peck drilling and slower speeds to work-harden less
- High-pressure coolant (70+ bar) is critical for deep hole drilling
Plastics (ABS, Nylon, POM, PC)
- Moderate spindle speeds (6,000-12,000 RPM)
- Sharp tools to prevent melting and burr formation
- Use single-flute or two-flute cutters for best chip evacuation
- Compressed air cooling often sufficient (flood coolant can cause swelling)
- Clamp parts securely as plastics tend to flex during machining
Titanium and Superalloys
- Low spindle speeds (500-2,000 RPM)
- Very low feed rates (0.02-0.08 mm/tooth)
- Use variable helix end mills to reduce chatter
- High-pressure coolant (70+ bar) is essential
- Maximize radial engagement — avoid light cuts that work-harden the surface
- Trochoidal and high-feed milling reduce heat concentration
Programming Best Practices
- Always simulate before cutting — CAM simulation catches 95% of collision and gouge errors
- Use G54-G59 work offsets — Allows multiple parts on the same machine with zero programming changes
- Include safety blocks — Start each program with G90 G80 G40 G17 G21 (absolute, cancel cycles, cancel comp, XY plane, mm)
- Avoid rapid moves near the part — Use G00 only in safe retract positions; use G01 for approach moves
- Document cutting parameters — Keep SFM (surface feet per minute) and IPT (inches per tooth) records for repeat jobs
- Peck drill deep holes — For depths exceeding 3x diameter, use pecking (G73 or G83) to break chips
- Use tool breakage detection — Program tool length checks between operations for lights-out machining
Post-Processing Considerations
The post-processor converts CAM-generated toolpaths into machine-specific G-code. Key considerations:
- Machine kinematics — 5-axis post-processors must account for the specific rotary axis configuration (head-head, table-table, or mixed)
- Output format — Some machines require .NC, others .NCC or .PIM files
- Tool change sequence — Verify the post-processor includes proper tool change macros (M06, tool call, G43 offset)
- High-speed machining — Enable look-ahead (G05.1 Q1 on Fanuc) for smoother high-feed finishes
Programming at MFGABC
Our CNC programming team uses Siemens NX CAM and Mastercam for all programming work. We maintain a library of post-processors calibrated to each machine in our shop. Every program undergoes virtual simulation before touching steel, reducing setup time and crash risk.
→ Related: CNC Machining Overview Guide
→ Related: Tolerance Standards Guide