Coordinate Systems and Positioning
Concept
Understanding coordinates is the single most important foundational skill in CNC programming. This page covers Cartesian coordinates, the right-hand rule, machine vs work coordinate systems, work offsets G54–G59, absolute vs incremental motion, rotary axes, and reference return.
Why It Matters
Coordinate errors are not cosmetic: a 0.1 mm offset that shifts a hole pattern off the part can turn a batch of good parts into scrap. Coordinate mistakes are also silent — the machine moves smoothly, the spindle sounds normal, and the part only fails inspection later. That is why understanding coordinates is not optional.
How It Works
Cartesian Coordinate System
A point in space is defined by its X, Y, Z coordinates relative to an origin. The Cartesian coordinate system uses three mutually perpendicular axes. On a vertical mill:
- X axis — tool motion relative to the workpiece in the left/right direction
- Y axis — tool motion relative to the workpiece in the in/out direction
- Z axis — tool motion relative to the workpiece in the up/down direction
Positive and negative directions follow the right-hand rule: point your right thumb in +X, your index finger in +Y, and your middle finger in +Z. This fixes the relative directions of the three axes, but it does not by itself tell you which physical direction on a specific machine is +X — that is defined by the machine builder. On a standard vertical mill, +Z is up (away from the table). On a lathe, Z is along the spindle and +Z points away from the chuck.
Mill vs Lathe Axes
The axes are named consistently, but the physical machine and the meaning of X differ between milling and turning.
Vertical Machining Center (VMC)
- Z: spindle up/down. +Z moves the spindle away from the table.
- X: tool relative to workpiece left/right. +X means the tool moves to more positive X relative to the part.
- Y: tool relative to workpiece in/out. +Y means the tool moves to more positive Y relative to the part.
CNC Lathe
- Z: along the spindle bore. +Z moves the tool away from the chuck.
- X: radial. In this page’s lathe examples, X is programmed as a diameter, not a radius. X40 means the tool tip is on a 40 mm diameter, 20 mm from center. Moving from X40 to X30 is a radial depth of cut of 5 mm. Some controls and operations use radius programming or cross-center facing; this page uses diameter mode throughout.
- C axis (optional): spindle rotation indexed as a position. Used for milling flats, drilling cross-holes, and driven tooling.
The diameter convention on lathes is the single most common source of confusion for programmers coming from milling. In this page’s lathe examples, the programmed X value is the finished diameter you want. Cross-center facing and rear-turret configurations are exceptions; verify against the machine manual.
Rotary Axes A, B, C
Rotary axes rotate about a linear axis. By the right-hand rule:
- A: rotation about X
- B: rotation about Y
- C: rotation about Z (or spindle on a lathe)
By the right-hand rule, point your thumb along the positive direction of the corresponding linear axis; your curled fingers indicate the positive rotation direction about that axis. On a 5-axis machine, these let the spindle tilt or the table rotate so the tool can approach angled surfaces.
Positive vs Negative Direction on a Real Machine
The programmed coordinate is defined relative to the workpiece, not relative to your eye. On a fixed-spindle, moving-table machine, to make the tool relative to the workpiece move +X, the table actually moves in the opposite physical direction. The controller and machine builder have already accounted for this: when you program X50, the controller commands the physical axis position that places the tool at X50 in work coordinates. You do not need to reverse signs in the program. Always read +X as "tool moves to more positive X relative to the part," not as "table moves right."
On a lathe in diameter mode, +X means larger diameter (away from spindle centerline). If you touch off the OD and enter the measured diameter into the X geometry offset, the controller computes the centerline automatically. Cross-center facing and rear-turret configurations are exceptions and must be checked against the machine manual.
Datum Strategy and Work Zero Placement
Where you place work zero is a process decision, not a given. On a milled rectangular block, the convention is the top-left corner (or top-right depending on shop standards), with Z0 on the top face. This matches how the drawing dimensions features. On a turned part, work zero is almost always the front finished face, with X0 on centerline. Placing work zero at the drawing datum minimizes arithmetic: every programmed coordinate comes straight from the print without offset calculations.
When a drawing uses a datum that is not a machined edge — for example a center bore or a hole pattern — the setup procedure must establish that datum first (bore it, or find it with an indicator) before setting the work offset. Programming G54 on a rough corner when the drawing dimensions from a finished hole introduces the corner's runout into every feature.
Machine Coordinate System
The machine coordinate system has its origin at machine zero. When the machine is turned on and homed, each axis moves to a reference marker or home switch; the machine then knows its current position relative to machine zero through encoders or scales. The reference return position, machine zero, and the tool-change position are not necessarily the same physical point — their relationship is defined by the machine builder and must be checked in the documentation.
G53 switches to machine coordinates for one block only. It is non-modal and used for machine-specific positions like tool change or pallet change, never for part programming. Example: G90 G00 G53 Z0 moves Z rapidly to machine coordinate Z0 for one block. Whether that position equals the reference return position depends on the machine builder. G53 is useful when you need the tool to go to a fixed physical location — the tool-change position, a chip-pan drain, or a pallet — regardless of which work offset is active. Machine zero, the reference position, and the tool-change position are not all the same physical point; check the machine documentation.
Reference Return: G28 and G30
After a program finishes, you often want the tool to return to a known safe position. G28 returns the specified axes to machine reference (home) via an intermediate point. The intermediate point is interpreted according to the current G90/G91 mode. Typical ending:
G91 G28 Z0 (retract Z to home, incremental from current)
G28 X0 Y0 (then X/Y to home)
M30
The G91 in front of G28 Z0 tells the controller "the intermediate point is zero relative to current Z, then go home." After this block, G91 remains active, so you must restore G90 before any subsequent absolute coordinate. G30 (secondary reference) support and target position depend on the controller; this page does not prescribe a universal return sequence.
Work Coordinate System (G54–G59)
The work coordinate system (WCS) has its origin at the workpiece datum — typically a corner or center of the part. You set this origin using a work offset. The machine stores multiple work offsets:
| Code | Purpose |
|---|---|
| G54 | Primary work offset (most common) |
| G55 | Second fixture / second workpiece |
| G56 | Third fixture |
| G57–G59 | Additional fixtures |
For XY without rotation, scaling, or local offset: machine coordinate = G54 origin (in machine coords) + programmed coordinate. You touch off the part corner with an edge finder or probe, enter that machine position into G54, and the controller computes the rest. Z with tool length offsets follows a separate setup chain and is not described by this XY formula.
How Work Offsets Are Set
On a mill, the standard touch-off procedure is:
- Clamp the part in the vise or fixture.
- Install an edge finder or dial indicator in the spindle.
- Jog the spindle until the edge finder touches the left edge of the part; the controller reads the current X machine position.
- Add half the edge finder tip diameter (typically +0.100" or 3 mm) and enter this value into G54 X.
- Repeat for Y on the front edge.
- For Z, first set the tool length H offset using your tool length setter or a known height gauge. Then touch a calibrated tool to the part top and set the workpiece Z datum in G54. Do not write an uncalibrated spindle-nose reading directly into G54; the H offset and the work Z are separate values.
Example: a Ø6 edge finder. After calibration, when the edge finder outer edge contacts the left edge and the machine X at the spindle center reads -203, the edge itself is at X = -200. You enter -200 into G54 X, not -203 — omitting the radius correction gives a 3 mm error. Applying it with the wrong sign gives a 6 mm error, equal to the tip diameter in this Ø6 example. When using a probe, the machine touches the edges and writes the offset values automatically.
Multiple Workpieces
When you machine four identical parts on one tombstone, you do not need four programs. Set G54 at part 1, G55 at part 2, G56 at part 3, G57 at part 4. The same program runs four times, switching work offsets. This is the most common use of G55–G59 in production.
Absolute vs Incremental Programming
This is where new programmers get confused. Two modes control how coordinates are interpreted:
| Mode | Code | Meaning | Example |
|---|---|---|---|
| Absolute | G90 | Coordinates refer to work zero | X50 = "go to X50" |
| Incremental | G91 | Coordinates refer to current position | X50 = "move 50 mm in +X" |
Example: Start at X0. G90 G01 X50 ends at X50. G91 G01 X50 also ends at X50 (because you started at 0). But start at X20: G90 G01 X50 ends at X50; G91 G01 X50 ends at X70. The same number produces a different result depending on the mode. Always know which mode you are in, and always restore G90 after using G91 in a subprogram.
Most manual programs are written entirely in G90 because it matches how a drawing dimensions features — every hole has an absolute location from the datum. G91 is useful inside subprograms where you repeat a pattern by stepping a fixed distance, and in G28 return moves. Mixing G90 and G91 within one program is legal but must be deliberate: every mode switch is a potential place to forget to switch back.
If the work offset is wrong by 2 mm in X, every hole and edge on the part shifts 2 mm. The program may look perfect on screen but the part is scrap. Coordinate errors are systematic — they affect every feature, not just one. A probe or edge finder only measures where the tool touched; it does not know whether you touched the left edge or the right edge, or whether you added the tip radius on the correct side. Always read back the offset values and sanity-check them against the machine position before closing the setup.
Example: Touching Off G54 on a Mill
Same Ø6 mechanical edge finder, work origin at the lower-left corner of the part. Machine +X moves the tool to the right relative to the part; machine +Y moves the tool away from the operator. Touch the left edge: when the edge finder trips, spindle center machine X = -203, so the edge itself is at X = -200. Enter -200 into G54 X. Touch the front edge: spindle center machine Y = -103, so the edge is at Y = -100. Enter -100 into G54 Y. Optionally verify the width by touching the right edge: spindle center machine X = -147, right edge at X = -150; width = -150 - (-200) = 50 mm. Do not overwrite G54 X with the right-edge value — the left edge is the datum. Z follows the calibrated tool and H-offset procedure described above. A mechanical edge finder requires manual radius compensation: +3 mm when touching the left/front datum edges, −3 mm when touching the right edge for width verification. A probe writes offsets automatically and is not mixed into this hand calculation.
Common Mistakes
- Forgetting to restore G90 after a G91 subroutine — subsequent absolute moves become incremental and accumulate errors.
- Treating G53 as modal — it is non-modal and active only for the block it appears in.
- Wrong corner for work zero — programming G54 on the wrong edge shifts all features.
- Confusing diameter and radius on a lathe — in diameter mode, the programmed X is the finished diameter; check the mode before cutting.
- Forgetting the edge-finder tip radius — omitting the radius correction gives a 3 mm error; using the wrong sign gives a 6 mm error (equal to the tip diameter in this Ø6 example).
- Misreading G90/G91 state at G28 — the intermediate point is interpreted according to the current mode; confirm which is active before writing the return block.
Practice
1. Point A is (5,8), point B is (-5,18). What are ΔX and ΔY?
Show answer
ΔX = -5 - 5 = -10 mm. ΔY = 18 - 8 = +10 mm.
2. In G91 mode from X20, you write X30. Where do you end up? Where would G90 put you?
Show answer
G91: X20 + 30 = X50. G90: X30. The same number means a different target depending on mode.
3. The G54 origin is at machine position (-300, -200). A hole is at (20,10) in work coordinates. What is its machine position? (No rotation, scaling, or local offset.)
Show answer
Machine position = G54 origin + work coordinate = (-300+20, -200+10) = (-280, -190). Machine zero itself is (0,0) in machine coordinates.
4. Why must you always return to G90 after a G91 subprogram?
Show answer
G91 is modal. If you leave it active, the next coordinate line that omits G90 (and whose author assumes absolute positioning) will instead move incrementally, accumulating position errors.
5. On a lathe you program X40 to X30. What is the radial depth of cut?
Show answer
X is diameter, so radial depth = (40 - 30)/2 = 5 mm. Not 10 mm.
Sources
- Haas Mill Part Setup — work offset setup procedure.
- Coordinate conventions follow ISO 841 machine axis standard; verify on your specific machine documentation.
- All setup values and example coordinates are classroom teaching assumptions.