Visual walkthrough — Distance formula in 3D
Everything below is built from zero. If a symbol appears, it was drawn first.
Step 0 — What the words and symbols mean
Before any triangle, let us agree on the picture of "3D space".
We will call our two points:
- — the subscript 1 just labels "the first point".
- — subscript 2 labels "the second point".
Our goal is the number = the straight-line length from to .

In the figure: the three axes meet at the origin (gray), is blue, is orange, and the red dashed segment is the mystery length we want to compute. Right now it just floats diagonally through space — no triangle yet.
Step 1 — Turn the two points into a box
WHAT. Draw a rectangular box (a cuboid) whose faces are parallel to the walls of the room (the coordinate planes), with and sitting at opposite corners.
WHY. A diagonal floating in space is hard to measure directly. But the box's edges run neatly along the axes, and edges along axes are things we can measure just by subtracting coordinates. This trick converts a hard diagonal into easy right-angle geometry — the same reason we lean on Pythagoras at all.
PICTURE.

The three edge lengths of the box are the coordinate differences:
Reading each symbol where it sits:
- is how far apart and are along x only — the length of the box (green edge).
- is the gap along y only — the depth of the box (blue edge).
- is the gap along z only — the height of the box (orange edge).
Step 2 — Look only at the floor
WHAT. Ignore height for a moment. Stare straight down at the bottom face of the box — a flat rectangle whose two edges are and . Draw its diagonal and call it .
WHY. The floor is a flat 2D world. In flat 2D we already own a rule for the diagonal of a rectangle: Distance formula in 2D, which is just Pythagoras. So we solve the easy 2D piece first, then deal with height separately.
PICTURE.

The edges and meet at a perfect corner (because the x-axis is perpendicular to the y-axis). That right angle is exactly what Pythagoras demands, so:
Term by term:
- — the square of the floor diagonal (the thing we're solving for on the floor).
- — square of the horizontal edge.
- — square of the depth edge.
- The plus is legal only because the two edges are perpendicular.
We keep it as (not ) on purpose — we're about to plug it straight into another Pythagoras, and squares combine cleanly.
Step 3 — Stand the diagonal up
WHAT. Now bring height back. Build a new right triangle whose two legs are:
- the floor diagonal (lying flat on the ground), and
- the vertical edge (going straight up from the far floor corner to ).
Its hypotenuse is the body diagonal — our target .
WHY. The vertical edge points straight up, which is perpendicular to the entire floor. So it is perpendicular to too (because lies inside the floor). Perpendicular legs ⇒ Pythagoras applies again, cleanly, a second time.
PICTURE.

Reading it:
- — square of the true straight-line distance (the red hypotenuse).
- — the floor diagonal squared, standing in as one leg.
- — the vertical rise squared, the other leg.
This is the "second Pythagoras" the parent note promised: floor first, then the climb.
Step 4 — Substitute the floor back in
WHAT. We know from Step 2. Slot it into Step 3.
WHY. We never actually cared about by itself — it was scaffolding. Replacing removes the middleman and leaves everything in terms of the three edges we can compute directly from coordinates.
Three squares, all added — one per direction of space.
Step 5 — Take the root, and watch the bars disappear
WHAT. Undo the square on by taking the (positive) square root.
WHY. We solved for , but we want . A distance is positive, so we take the positive root.
Now substitute , and likewise for . Here's the payoff: squaring a number and its absolute value give the same result, since . So the bars are pointless inside a square — they simply drop out:
- — squared x-gap (was edge ).
- — squared y-gap (was edge ).
- — squared z-gap (was edge ).
- outer — turns "square of distance" back into "distance".
This is the magnitude of the vector — see Vectors and magnitude.
Step 6 — Edge case A: the two points share a plane (one difference is zero)
WHAT. Suppose , so : both points sit at the same height.
WHY show this? To prove the 3D formula doesn't break — it should quietly become the 2D formula, because with equal heights nothing pokes up in the z-direction.
PICTURE.

The box flattens into a rectangle on one plane. Plug :
That is exactly Distance formula in 2D. So 2D is just 3D with a flat box. Same logic covers "same x" or "same y" — any one zero difference collapses the box onto a face, and the formula still holds because we simply add a zero.
Step 7 — Edge case B: the points coincide (all differences zero)
WHAT. Suppose and are the same point: , , .
WHY. A trustworthy distance rule must return zero when there's no gap — and only then.
The box shrinks to a dot; there's no diagonal to measure. And notice the reverse is also true: if , then each squared term must individually be (squares can't be negative, so a sum of squares is zero only when every term is zero) — forcing the points to coincide. The formula is honest in both directions.
Step 8 — Edge case C: order of subtraction never matters
WHAT. Does it change the answer if you compute instead of ? (I.e. measuring from to instead of to .)
WHY. People panic about "which point goes first". Let's kill that worry visually and algebraically.
The two differences are just negatives of each other: . But we square it, and squaring erases the sign:
So . The string between two points has one length no matter which end you start from. The box is identical either way.
The one-picture summary

This single figure carries the whole story: the box with edges ; the green floor diagonal satisfying ; the red body diagonal satisfying ; and the final combined formula. Trace the arrows: floor first, then up, then substitute.
Recall Feynman: tell it to a 12-year-old
Two ants sit in a shoebox — one in a bottom corner, one in the opposite top corner. I want the length of the invisible string joining them straight through the air. I can't walk that string, but I can build it in two easy hops. Hop 1: walk across the floor from below the first ant to below the second — that floor path itself is the diagonal of a rectangle, so its length comes from the ordinary flat rule: square the length, square the width, add, root. Hop 2: now the string, the floor-diagonal, and the box's height make a new flat right triangle standing on its edge, because "up" is perpendicular to the floor. Apply the same flat rule again. Stack the two hops and you get one clean rule: square the differences in x, y, and z, add all three, take the square root. The bars for "no negatives" vanish on their own because squaring already forgets the minus signs — which is also why it makes no difference which ant you start from.
Active Recall
Why do we build a box around and ?
How many times is Pythagoras used, and where?
Why can we drop the absolute-value bars in the final formula?
What happens to the formula when ?
What does force about the two points?
Why is the same as ?
Connections
- Distance formula in 3D — the parent result this page derives in pictures.
- Coordinate axes and octants in 3D — the three perpendicular directions the box is aligned to.
- Distance formula in 2D — recovered in Step 6 when one difference is zero.
- Vectors and magnitude — .
- Section formula in 3D — reuses the same coordinate differences.
- Direction cosines and direction ratios — the edges become direction ratios.
- Equation of a sphere — the set of points at a fixed distance from a centre.