15.8 NC/CNC Machines & CNC Part Programming

Key Takeaways

  • NC/CNC machines and CNC programming are named explicitly in the Machining bullet of the CIL Mechanical Paper-II syllabus.
  • G codes are preparatory functions that control machine motion and modes, while M codes are miscellaneous functions that control auxiliary equipment such as the spindle and coolant.
  • In absolute programming with G90 all coordinates are measured from the program origin, whereas in incremental programming with G91 each coordinate is measured from the previous point.
  • G02 specifies clockwise circular interpolation and G03 anticlockwise, with the arc centre normally given by the incremental I, J and K offsets from the start point.
Last updated: August 2026

NC, CNC and DNC

TermMeaning
NCNumerical Control; the programme is fixed in hardware or on punched tape, and editing requires a new tape
CNCComputer Numerical Control; a dedicated computer holds the programme, which can be edited, stored and re-run at the machine
DNCDirect or Distributed Numerical Control; a central computer serves programmes to several machines over a network

The decisive advance of CNC over NC is programme storage and editing at the machine, together with the ability to hold canned cycles, tool offsets and compensation tables in memory.

Point-to-point versus continuous path

ControlBehaviourApplication
Point-to-point (positional)Moves to a position; the path between points is unimportantDrilling, tapping, spot welding, punching
Continuous path (contouring)The path itself is controlled at every instantMilling, turning, profiling, flame cutting

Open versus closed loop

LoopCharacter
Open loopStepper motors; no position feedback; cheaper; position assumed from pulse count; a missed step is undetected
Closed loopServo motors with encoders or linear scales providing feedback; errors are detected and corrected; used on all production machines

Axis Conventions

The right-hand rule fixes the axes:

  • Z is always along the spindle axis, with positive Z moving the tool away from the workpiece.
  • X is the longest axis of motion perpendicular to Z, normally horizontal.
  • Y completes the right-handed set.
  • Rotary axes A, B and C rotate about X, Y and Z respectively.

On a lathe, X is the diametral direction, and X coordinates are conventionally programmed as diameters rather than radii — a persistent source of error for those moving between milling and turning.

A fundamental convention: motion is always described as the movement of the tool relative to the workpiece, even when the machine physically moves the table instead.

Interpolation

TypeCodePath
Rapid positioningG00Fastest available; path not guaranteed straight; never cutting
Linear interpolationG01Straight line at programmed feed rate
Circular, clockwiseG02Arc
Circular, anticlockwiseG03Arc
Helical, parabolic, cubicVariesAdvanced controllers

Rapid moves must never be used for cutting: the path between two points under G00 may be a dog-leg rather than a straight line, and the feed is uncontrolled.

G Codes and M Codes

G codes are preparatory functions that set the machine's mode of operation. M codes are miscellaneous functions that switch auxiliary equipment. Keeping the two categories apart is the most common single question on this topic.

Common G codes

CodeFunction
G00Rapid traverse
G01Linear interpolation
G02 / G03Circular interpolation, clockwise / anticlockwise
G04Dwell
G17 / G18 / G19Plane selection: XY / XZ / YZ
G20 / G21Inch / metric units
G28Return to machine reference (home)
G40 / G41 / G42Cutter compensation cancel / left / right
G43 / G49Tool length compensation on / cancel
G54 - G59Work coordinate systems
G90 / G91Absolute / incremental positioning
G94 / G95Feed per minute / feed per revolution
G96 / G97Constant surface speed / constant spindle rpm
G80Cancel canned cycle
G81 / G83 / G84Drilling / peck drilling / tapping cycles

Common M codes

CodeFunction
M00 / M01Programme stop / optional stop
M03 / M04 / M05Spindle clockwise / anticlockwise / stop
M06Tool change
M08 / M09Coolant on / off
M30Programme end and rewind
M98 / M99Subprogramme call / return

Absolute Versus Incremental

This distinction produces more programming errors than any other.

ModeCodeCoordinates measured from
AbsoluteG90The fixed programme origin (work zero)
IncrementalG91The previous point

To move through the points (10,10), (30,10) and (30,40):

Absolute (G90)Incremental (G91)
X10 Y10X10 Y10
X30 Y10X20 Y0
X30 Y40X0 Y30

Absolute programming is safer because an error at one point does not propagate; in incremental mode every subsequent position inherits the error. Absolute is therefore standard practice, with incremental reserved for repeated patterns and subprogrammes.

Circular Interpolation and I, J, K

An arc requires the endpoint and the centre. The centre is normally specified by I, J and K, which are the incremental offsets from the arc start point to the arc centre, along X, Y and Z respectively.

To cut a quarter circle of radius 20 anticlockwise from (20,0) to (0,20) with centre at the origin:

G03 X0 Y20 I-20 J0

The I value of minus 20 is the X distance from the start point (20,0) to the centre (0,0). Many controllers also accept an R word giving the radius directly, which is simpler but ambiguous for arcs greater than 180 degrees, where the sign of R selects between the two possible arcs.

Cutter Radius Compensation

The programmer wants to describe the finished part profile, not the path of the cutter centre, which lies one cutter radius away. Cutter compensation lets the controller make that offset automatically using a radius value stored in an offset table.

CodeMeaning
G41Compensation left of the direction of travel
G42Compensation right of the direction of travel
G40Cancel compensation

Left and right are judged looking along the direction of tool travel. For conventional climb milling of an external profile, G41 is usual.

The practical benefit is decisive: if the cutter is reground to a smaller diameter, or a different cutter is fitted, only the offset value in the table changes — the programme itself is untouched. The same mechanism is used to leave a finishing allowance, simply by entering an offset larger than the true radius.

Tool length compensation (G43) works similarly in Z, storing each tool's length offset so that programmes can be written to the part datum irrespective of how far each tool protrudes from its holder.

Canned Cycles

A canned cycle replaces many blocks with one. For drilling a series of holes, instead of programming rapid down, feed to depth, rapid out for every hole:

G81 X__ Y__ Z-25 R2 F100

where Z is the final depth, R the retract plane and F the feed. Subsequent X and Y coordinates repeat the cycle at each new position until cancelled by G80.

CyclePurpose
G81Simple drilling
G82Drilling with dwell at the bottom, for a flat-bottomed counterbore
G83Peck drilling, retracting to clear chips; essential for deep holes
G84Tapping
G85Boring, feeding out

A Complete Worked Programme

Milling a 60 by 40 mm rectangular pocket profile, 5 mm deep, with a 10 mm diameter end mill, work zero at the lower left corner of the profile:

O0001                     (programme number)
G21 G90 G94 G17           (metric, absolute, feed/min, XY plane)
G54                       (work coordinate system)
T01 M06                   (tool 1, end mill 10 mm)
S1200 M03                 (spindle 1200 rpm clockwise)
G43 H01 Z50               (tool length offset, safe height)
G00 X-15 Y-15             (rapid to approach point clear of part)
Z5                        (rapid to clearance plane)
G01 Z-5 F100              (feed to depth)
G41 D01 X0 Y0             (cutter comp left, approach profile)
G01 X60 F200              (cut along bottom edge)
Y40                       (cut up right edge)
X0                        (cut along top edge)
Y0                        (cut down left edge)
G40 X-15 Y-15             (cancel compensation, move clear)
G00 Z50                   (retract)
M05                       (spindle stop)
M09                       (coolant off)
G28 G91 Z0                (return to home in Z)
M30                       (programme end and rewind)

Note the structural discipline: safety block first setting units and modes, approach clear of the part before engaging compensation, cancel compensation clear of the part, and retract before stopping the spindle. Those four habits prevent the great majority of crashes.

Programming Methods

MethodDescription
ManualG code written by hand; suits simple prismatic parts
ConversationalMenu-driven at the machine control; fast for shop-floor programming
CAM (computer aided)Toolpath generated from the CAD model and post-processed; essential for sculptured surfaces

For a maintenance workshop producing one-off spares from drawings, manual and conversational programming usually suffice. For die and mould work or three-dimensional surfaces, CAM is not optional.

Test Your Knowledge

In CNC programming, the difference between G codes and M codes is that:

A
B
C
D
Test Your Knowledge

Under G91 incremental programming, each coordinate is measured from:

A
B
C
D
Test Your Knowledge

In circular interpolation, the words I, J and K normally specify:

A
B
C
D
Test Your Knowledge

The principal practical advantage of cutter radius compensation is that:

A
B
C
D