CNC Programming

Chapter 8
CNC Milling and Machining-Centre Programming

Bachelors Program in Machine Technology
CNC Programming   •   Bachelor

CNC Milling and Machining-Centre Programming

Introduction

CNC milling converts a digital part description into controlled motion of a cutting tool relative to a workpiece. Modern machining centres combine milling with drilling, boring, tapping, probing, tool changing and, in some cases, rotary-axis positioning. Successful programming therefore requires more than memorising G-codes: the programmer must understand coordinate systems, cutter geometry, machine kinematics, cutting conditions, tool compensation, workholding and verification.

This chapter develops programming methods for face milling, pockets, slots, contours, drilling, boring, tapping, helical interpolation and multi-setup machining. Examples use common Fanuc-style conventions, but exact syntax varies by controller. Always consult the machine manual before executing a program.

Learning Objectives

After studying this chapter, the reader should be able to:

  • select appropriate work planes and coordinate systems;
  • create safe programs for facing, pocketing, slotting and contouring;
  • apply cutter-radius and tool-length compensation correctly;
  • use work offsets and canned cycles for hole-making operations;
  • program helical interpolation and evaluate its geometric limits;
  • plan multiple setups while preserving datums and inspection control;
  • verify, simulate and document CNC programs safely.

1. Machining-Centre Coordinate Systems and Planes

A vertical machining centre commonly uses the right-hand coordinate system: X and Y define the working plane and Z defines tool-axis motion. Positive Z usually moves away from the workpiece, although the sign convention must be confirmed for the machine.

The principal modal plane-selection codes are:

CodePlaneTypical use
G17X–Y planeNormal vertical milling and drilling
G18X–Z planeTurning-style or side-plane circular interpolation
G19Y–Z planeSide-plane milling

G17 is normally active for vertical machining. Plane selection determines which axes are interpreted by circular interpolation, cutter compensation and some canned-cycle parameters. A program should state the intended plane rather than relying on a previous modal condition.

Machine, work and tool coordinates

The machine coordinate system is established by the machine builder and generally cannot be changed by the part program. A work offset, such as G54, defines the programmed part datum within that machine system. Tool length compensation accounts for differences in tool gauge length. Cutter-radius compensation accounts for the radius of the cutting tool when programming a nominal contour.

A safe initialization block often includes:

G21 G17 G90 G40 G49 G80
G54

Here G21 selects millimetres, G17 selects the XY plane, G90 selects absolute programming, G40 cancels cutter compensation, G49 cancels tool-length compensation, G80 cancels canned cycles, and G54 selects the first work offset. Code meanings can differ on special-purpose controls, so the machine manual has authority.

Absolute and incremental programming

With G90, coordinates are measured from the active work origin. With G91, each coordinate is measured from the current tool position. Absolute programming is generally easier to audit; incremental programming is useful for repeated patterns but can accumulate errors if poorly managed.

2. Cutting Conditions and Toolpath Planning

A milling program must connect geometry with cutting conditions. Important variables include spindle speed, feed rate, axial depth of cut, radial width of cut, tool diameter, material and coolant strategy.

For a rotating tool, cutting speed is related to spindle speed by:

n = (1000 Vc) / (π D)

where n is spindle speed in revolutions per minute, V_c is cutting speed in metres per minute, and D is tool diameter in millimetres. The factor 1000 converts metres to millimetres. This equation assumes that the stated cutting speed refers to the tool periphery.

Feed rate for a milling cutter is:

Vf = n z fz

where V_f is feed rate in millimetres per minute, z is the number of effective teeth, and f_z is feed per tooth in millimetres per tooth. The calculation assumes all stated teeth participate effectively. Runout, chip thinning, interrupted cuts and adaptive strategies may require adjustment.

Worked example. A four-flute, 20 mm cutter is recommended to run at 120 m/min with a feed per tooth of 0.08 mm/tooth. The spindle speed is:

n = (1000 × 120) ÷ (π × 20) ≈ 1,910 rev/min.

The feed rate is:

V_f = 1,910 × 4 × 0.08 ≈ 611 mm/min.

A practical program may use a nearby permitted value, such as S1900 and F610, after checking machine capability and workpiece conditions.

3. Tool Length and Cutter-Radius Compensation

Tool-length compensation

Tool length compensation shifts the programmed tool tip or gauge point along the tool axis. A typical sequence is:

T01 M06
G43 H01 Z50.

T01 selects tool 1, M06 changes the tool, and G43 applies positive length compensation from register H01. The tool should be clear of the work before compensation is activated. H-register numbering is commonly matched to tool numbering, but this is a shop practice rather than a universal requirement.

G49 cancels tool-length compensation. Cancellation should occur in a safe position, because the machine may move unexpectedly if compensation is cancelled near the workpiece.

Cutter-radius compensation

G41 applies left compensation and G42 applies right compensation when viewed in the direction of tool travel; G40 cancels it. “Left” and “right” refer to the side of the programmed path, not to the operator’s viewpoint.

A lead-in move is required so that the control can establish the offset gradually. A representative contour is:

G17 G90 G54
T02 M06
S2500 M03
G00 X-10. Y-10.
G43 H02 Z50.
G00 Z5.
G01 Z-3. F120.
G41 D02 X0. Y0. F300.
G01 X60. Y0.
G01 X60. Y40.
G01 X0. Y40.
G01 X0. Y0.
G40 X-10. Y-10.
G00 Z50.
M30

The D register contains the cutter-radius value or a control-specific compensation value. Compensation is valuable when the same nominal contour must be machined with tools of different diameters, but the programmed lead-in and lead-out must be long enough for the tool radius and control algorithm. Compensation should not be activated on a corner or cancelled without a suitable exit move.

4. Face Milling

Facing produces a flat reference surface and may establish the Z datum. A face-milling path should extend beyond the material boundary by a controlled amount, provide overlap between adjacent passes, and avoid unnecessary full-width engagement.

A typical sequence is:

G00 X-35. Y-25. Z5.
G01 Z-0.5 F150.
G01 X95. F700.
G00 Y-5.
G01 X-35. F700.
G00 Y15.
G01 X95. F700.
G00 Z50.

The actual coordinates depend on stock size, cutter diameter and desired step-over. Entry should occur outside the finished surface where possible. A climb-milling strategy is often preferred on CNC machines because backlash is controlled, but rigidity, material, tool geometry and machine condition remain decisive.

5. Pocket and Slot Milling

A pocket is a recessed area enclosed by boundaries. A slot is a narrow channel, often approximately the width of the cutter or intentionally wider. Programming options include:

  1. Contour-plus-raster machining: remove material in successive boundary-following or parallel passes.
  2. Helical entry: interpolate downward while moving around a circular path.
  3. Trochoidal or adaptive paths: maintain a relatively controlled engagement in difficult materials.
  4. Canned milling cycles: available on some controls, but less universal than drilling cycles.

For a rectangular pocket, roughing should leave a small allowance for finishing. The finishing pass should use a stable radial engagement and avoid plunging directly into solid material unless the cutter is designed for it.

For a slot cut with a tool whose diameter equals the required slot width, the tool centreline follows the slot centreline. If the slot is wider than the tool, the toolpath must be offset from the centre and may require multiple passes. If the slot is narrower than the cutter, the operation is geometrically impossible without a smaller tool.

A simple slot program may be:

G00 X10. Y25. Z5.
G01 Z-4. F120.
G01 X80. F450.
G00 Z5.

This assumes the cutter can plunge safely and that X10 to X80 is the slot centreline. A ramp, pilot hole or helical entry is safer for many tools.

6. Contour Milling and Corner Treatment

Contour programming follows the boundary of a component. The programmer must distinguish between the part boundary and the tool-centre path. Without cutter compensation, the centreline must be calculated by offsetting the boundary by the tool radius. With compensation, the program can describe the nominal boundary, provided the control supports the geometry and the lead-in is valid.

Sharp internal corners cannot be produced with a round cutter smaller than the required corner radius. The minimum internal radius is approximately the cutter radius for a conventional end mill. A smaller corner radius requires a smaller cutter, a corner-relief strategy or a secondary operation.

External corners may be sharp in the programmed geometry, but the cutter path physically rounds them. The finished corner radius is influenced by tool radius, compensation method, feed, machine dynamics and tool deflection.

7. Drilling, Boring and Tapping

Hole-making operations are frequently programmed with canned cycles. Common Fanuc-style cycles include:

CycleFunction
G81Simple drilling
G82Drilling with dwell at the bottom
G83Peck drilling for deep or difficult holes
G84Tapping
G85Boring with feed in and feed out
G86Boring with spindle stop and rapid withdrawal

A modal drilling cycle remains active until cancelled with G80 or replaced by another cycle. Therefore, the program should clearly cancel the cycle before rapid travel to a location where drilling is not intended.

Example of simple drilling:

G17 G90 G54
T03 M06
S1800 M03
G43 H03 Z50.
G00 X20. Y20.
G98 G81 Z-18. R2. F180.
X60. Y20.
X60. Y50.
X20. Y50.
G80
G00 Z50.

Z is the final depth, R is the retract or clearance plane, and F is feed rate. G98 commonly returns to the initial point; G99 commonly returns to the R plane. The meaning should be verified on the controller.

G83 peck drilling divides the depth into increments. Pecking improves chip evacuation and reduces the risk of chip packing, but excessive retracts increase cycle time. A representative block is:

G83 G98 Z-40. R3. Q6. F120.

Q is the peck depth on many controls. The appropriate value depends on drill diameter, material, coolant and hole depth.

Boring

Boring enlarges or corrects an existing hole. Unlike drilling, it can achieve improved size, straightness and surface finish. The programmer must consider spindle orientation, withdrawal direction and whether the boring tool should retract at feed or rapid. A boring cycle should never be copied between machines without checking its exact syntax.

Tapping

Rigid tapping synchronises spindle rotation and axial feed. For a metric thread, the ideal feed is:

F = n p

where F is feed in millimetres per minute, n is spindle speed in revolutions per minute, and p is thread pitch in millimetres per revolution. For example, an M8 × 1.25 tap at 500 rev/min requires F = 500 × 1.25 = 625 mm/min. This assumes rigid tapping, a correctly selected pitch, no programmed feed override disturbance and a control configured for the tap cycle.

A typical cycle is:

G84 Z-16. R2. F625.

The tap drill diameter must be selected from the thread standard and material requirement; it is not simply the nominal thread diameter minus an arbitrary amount.

8. Helical Interpolation

Helical interpolation combines circular motion in a selected plane with linear movement along the tool axis. In G17, an XY arc is combined with Z movement. It is useful for circular pockets, large holes, ramps and controlled entry.

A full circle generally requires two semicircular blocks because many controls do not accept a single 360° arc. Example:

G00 X40. Y30. Z5.
G01 Z0. F150.
G03 X40. Y30. I-10. J0. Z-1. F300.
G03 X40. Y30. I-10. J0. Z-2.
G03 X40. Y30. I-10. J0. Z-3.

Here the tool centre traces a circle of radius 10 mm while descending 1 mm per revolution. I and J specify the centre offset from the arc start in the selected plane. The tool must be suitable for the material and, for a pocket, the helical radius must account for cutter radius and required finished diameter.

Helical entry is not automatically safe. The ramp angle, chip load, cutter’s centre-cutting capability, coolant and machine rigidity must be checked. A helical path should terminate with a finishing contour if dimensional accuracy is important.

9. Work Offsets and Multiple Setups

A work offset is a controlled relationship between the part datum and machine coordinates. G54–G59 and extended offset systems may be used for different parts, vises or setups. The datum should be physically accessible, repeatable and inspectable.

A multi-setup component may be machined as follows:

  • Setup 1: face stock, establish Z0, rough and finish the primary features.
  • Setup 2: locate from machined datums, machine the reverse face and secondary holes.
  • Setup 3: use a rotary or angled fixture for side features if required.

The critical principle is datum continuity. If Setup 2 references an unmachined or poorly controlled surface, errors from Setup 1 may be compounded. Use locating pins, stops, soft jaws or a precision fixture, and record the offset values in the setup sheet.

When several identical parts are mounted simultaneously, separate work offsets can reduce repetitive zero-setting. However, each offset must be verified independently, and the program should make the active offset obvious.

10. Applied Case: Illustrative Two-Setup Aluminium Bracket

Background

An illustrative aluminium bracket is required with a faced top surface, a 60 mm × 35 mm pocket, four mounting holes and two counterbored holes on the reverse side. The stock is 100 mm × 70 mm × 20 mm.

Problem

The part must be produced with a controlled top datum, a 6 mm pocket depth and hole locations within the drawing tolerances. The second setup must preserve the relationship between the pocket and reverse holes.

Analysis

The first setup is assigned G54 with the upper-left corner of the stock as X0 Y0 and the top surface as Z0 after facing. A 16 mm four-flute end mill is used for roughing and a 10 mm end mill for finishing. Drilling is performed after pocket finishing so that chips from roughing do not obscure hole locations.

The second setup uses machined side and end datums against fixed stops. G55 is set with the same X–Y orientation as G54 wherever possible. This simplifies drawing interpretation and inspection, although the Z direction is established from the newly presented face.

Approach

The operation plan is:

  1. inspect stock and fixture condition;
  2. face the top surface;
  3. rough the pocket, leaving 0.3 mm radial and 0.2 mm floor allowance;
  4. finish pocket walls and floor;
  5. drill four mounting holes using G81;
  6. cancel the cycle and inspect the first setup;
  7. turn the part against controlled datums;
  8. face to final reverse thickness;
  9. drill and counterbore the reverse holes;
  10. inspect pocket size, hole position, thickness and burr condition.

Outcome

The work-offset method makes the relationship between features traceable. If the first article shows a hole-position error, the source can be investigated through the drawing datum, fixture location, offset entry and toolpath rather than by changing several unrelated coordinates.

Learning points

The case demonstrates that machining-centre programming is a process-planning activity. Correct G-code cannot compensate for an unstable fixture, an ambiguous datum or an unverified tool table. First-article inspection and documented offset control are essential parts of programming practice.

11. Verification, Safety and Professional Practice

Program verification should occur at several levels:

  • Syntax verification: check codes, decimal formats, tool calls and controller compatibility.
  • Geometric verification: simulate tool motion, cutter diameter, holders, fixtures and stock removal.
  • Process verification: check tool sequence, coolant, chip evacuation, workholding and inspection points.
  • Machine verification: conduct a dry run, single-block test or graphics check as appropriate.
  • First-piece verification: measure critical dimensions before continuing production.

Common causes of failure include incorrect G54 entry, wrong H or D register, active G91 mode, an uncancelled G81 cycle, an incorrect plane, insufficient clearance, tool diameter mismatch and confusing machine coordinates with work coordinates.

Safety requires controlled access, correct guarding, suitable personal protective equipment, secure workholding and adherence to local regulations and manufacturer instructions. A program should never be tested on a machine merely because it appears syntactically correct. Particular care is required with rapid moves, long tools, deep holes, heavy fixtures and rotary axes.

Digital simulation, collision checking and post-processors improve reliability, but they are not substitutes for engineering judgement. A simulation may omit real tool deflection, incorrect tool-table data, fixture looseness or an improperly measured work offset. AI-assisted code generation can help produce templates or identify modal risks, but generated code must be reviewed, simulated and authorised by a competent programmer. Accountability remains with the responsible engineer and operator.

12. Contemporary Developments and Employability

Current machining practice increasingly combines CAM systems, digital twins, probing, tool-condition monitoring and networked production data. In-process probing can automatically establish work offsets, measure features and compensate for predictable wear. High-speed machining and adaptive clearing reduce unnecessary engagement, while five-axis machines provide access to complex surfaces.

Nevertheless, fundamental skills remain employability requirements: reading engineering drawings, understanding datums and tolerances, selecting tools, interpreting cutting data, editing safe G-code, inspecting parts and communicating clearly with operators and quality personnel. A graduate who understands why a toolpath is correct is more valuable than one who merely copies a post-processed program.

Chapter Summary

CNC milling and machining-centre programming integrates coordinate systems, plane selection, tool compensation, work offsets, cutting conditions and safe process planning. G17 is normally used for XY milling, while G18 and G19 support other planes. Tool-length compensation uses an H register, and cutter-radius compensation uses G41 or G42 with a valid lead-in and lead-out. Facing, pocketing, slotting and contouring require attention to cutter geometry and engagement. Drilling, boring and tapping cycles improve consistency, but modal cycles must be cancelled deliberately. Helical interpolation provides controlled circular entry and pocketing. Multiple setups succeed only when datums, fixtures and offsets are repeatable. Simulation, dry runs and first-piece inspection are essential safeguards, and modern digital tools assist—but do not replace—professional judgement.

Key Terms

Work offset: The programmed relationship between a part datum and the machine coordinate system.

Machine coordinate system: The fixed coordinate framework established by the machine tool.

Plane selection: The choice of principal interpolation plane, such as G17, G18 or G19.

Tool-length compensation: Compensation for the measured length of a cutting tool.

Cutter-radius compensation: Control adjustment that offsets a programmed path by tool radius.

Lead-in: A move used to establish cutter compensation before the main contour.

Lead-out: A move used to leave a compensated contour safely.

Face milling: Removing material from a broad surface to create a flat face.

Pocket: An enclosed recessed feature machined below a surface.

Slot: A narrow channel produced by a cutting tool.

Contour milling: Machining along a specified two-dimensional boundary.

Canned cycle: A modal controller routine for repeated operations such as drilling.

Peck drilling: Drilling by repeated cutting increments and retracts.

Boring: Enlarging or correcting an existing hole with a boring tool.

Rigid tapping: Synchronized spindle and feed motion for producing threads.

Helical interpolation: Simultaneous circular motion and axial movement.

Datum: A theoretically exact reference used to locate or orient features.

Modal code: A code that remains active until cancelled or replaced.

Dry run: A controlled test of machine motion without normal cutting.

Post-processor: Software that converts CAM toolpaths into controller-specific code.

Review Questions

Short Answer Questions

  1. What is the function of G17 in a typical vertical machining-centre program?
  2. Why is a lead-in required when activating cutter-radius compensation?
  3. What is the difference between G98 and G99 in many drilling-cycle conventions?
  4. State two purposes of a work offset.
  5. Why must a canned drilling cycle be cancelled with G80 or replaced deliberately?

Long Answer Questions

  1. Explain how tool-length compensation and cutter-radius compensation differ, including their registers, activation methods and safety considerations.
  2. Describe a complete strategy for machining a rectangular pocket, from roughing and entry to finishing and inspection.
  3. Explain the operating principles and applications of G81, G83, G84 and boring cycles.
  4. Discuss the geometric and process factors that must be checked before using helical interpolation.
  5. Develop a datum and work-offset plan for a component requiring two machining setups.

Analytical / Application Questions

  1. A 20 mm cutter is required to run at 120 m/min with four teeth and a feed per tooth of 0.08 mm. Calculate spindle speed and feed rate, then recommend rounded machine settings.
  2. A tapping operation uses an M8 × 1.25 tap at 500 rev/min. Determine the synchronized feed rate and explain the assumptions behind the calculation.
  3. A finished pocket is 40 mm in diameter and is cut with a 10 mm end mill. Explain how you would select the tool-centre radius for a finishing path and how you would verify the result before cutting.

Multiple Choice Questions with Answers

Question 1

Which code normally selects the X–Y machining plane on a vertical machining centre?

A. G17

B. G18

C. G19

D. G40

Correct Answer: A. G17

Question 2

What is the primary purpose of an H register in a typical milling program?

A. Store cutter diameter

B. Store tool-length compensation

C. Select the work offset

D. Specify peck depth

Correct Answer: B. Store tool-length compensation

Question 3

Which code cancels an active canned drilling cycle?

A. G40

B. G49

C. G80

D. G98

Correct Answer: C. G80

Question 4

What is the feed rate for a four-flute cutter running at 1,910 rev/min with a feed per tooth of 0.08 mm?

A. 152.8 mm/min

B. 611.2 mm/min

C. 1,528 mm/min

D. 7,640 mm/min

Correct Answer: B. 611.2 mm/min

Question 5

Which cycle is commonly associated with peck drilling?

A. G81

B. G82

C. G83

D. G84

Correct Answer: C. G83

Question 6

In a typical Fanuc-style program, what does G43 activate?

A. Positive tool-length compensation

B. Cutter-radius compensation to the left

C. Incremental programming

D. Spindle orientation

Correct Answer: A. Positive tool-length compensation

Question 7

For an M8 × 1.25 tap at 500 rev/min, what synchronized feed is required?

A. 400 mm/min

B. 500 mm/min

C. 625 mm/min

D. 1,250 mm/min

Correct Answer: C. 625 mm/min

Question 8

Which operation is specifically intended to improve the size and straightness of an existing hole?

A. Facing

B. Boring

C. Slotting

D. Rough pocketing

Correct Answer: B. Boring

Question 9

What is a principal advantage of helical interpolation?

A. It eliminates the need for tool compensation

B. It allows controlled circular entry with simultaneous axial movement

C. It automatically establishes the work offset

D. It prevents all tool deflection

Correct Answer: B. It allows controlled circular entry with simultaneous axial movement

Question 10

Why is datum continuity important in multi-setup machining?

A. It increases spindle speed automatically

B. It prevents the need for coolant

C. It preserves the positional relationship between features

D. It makes every tool the same length

Correct Answer: C. It preserves the positional relationship between features

CNC Programming
Chapter 8 of 15