How to Derive the Distance Formula from the Pythagorean Theorem

The distance formula isn't something you memorize — it's something you discover. Here's how it falls out naturally from a right triangle hidden inside every pair of points.

By Petrus Sheya

July 1, 2026 · 6 min read

You already know how to measure distance along a straight road. Walk 3 blocks east. You traveled 3 blocks. Simple.

But what if you cut across the corner diagonally?

That diagonal shortcut is harder to measure. You can't count blocks. But there's a way to figure it out exactly, and it uses a result you probably learned in school but may have never connected to this problem: the Pythagorean theorem.


The city-blocks intuition

Picture a grid city. You're at intersection A. Your friend is at intersection B, somewhere to the northeast. To get there on foot, you have to follow the streets, walking east some number of blocks, then north.

Let's say A is at coordinates (1,2)(1, 2) and B is at (4,6)(4, 6). Walking the grid, you go 3 blocks east and 4 blocks north — for a total of 7 blocks.

But you're a bird. You fly straight from A to B. How far is that diagonal path?

That's the question the distance formula answers.

Drag either point. The right triangle forms automatically — the two legs are Δx and Δy, and the hypotenuse is the distance.

0224466881010Δx = 6Δy = 4A(1,2)B(7,6)
Δx6
Δy4
Δx² + Δy²52
Distance7.211

Drag the two points around. Watch what happens. The moment you place two points, a right triangle appears automatically. The horizontal leg is how far you travel east. The vertical leg is how far you travel north. The diagonal — the hypotenuse — is the actual straight-line distance.

The distance formula is just the Pythagorean theorem, dressed up in coordinate language.


Why the right triangle always appears

Here's the key observation. Given any two points A=(x1,y1)A = (x_1, y_1) and B=(x2,y2)B = (x_2, y_2), we can always build a right triangle with:

  • A horizontal leg from AA to the corner point C=(x2,y1)C = (x_2, y_1)
  • A vertical leg from CC straight up to BB
  • The hypotenuse from AA directly to BB

The corner CC sits at the same height as AA and the same horizontal position as BB. You can always find it. It always makes a right angle.

The length of the horizontal leg is x2x1|x_2 - x_1| — the horizontal gap between the two points. The length of the vertical leg is y2y1|y_2 - y_1| — the vertical gap.

We write these as Δx\Delta x ("delta x") and Δy\Delta y ("delta y"). The Δ\Delta symbol just means "change in."


The Pythagorean theorem, quickly

Before we apply it, let's make sure the theorem itself is vivid.

Take a right triangle with legs aa and bb and hypotenuse cc. Build a square on each side. The theorem says the two smaller squares together have exactly the same area as the big square.

a2+b2=c2a^2 + b^2 = c^2

Press Play to see squares grow on each side of the triangle. The two smaller squares fill exactly as much area as the big one.

a²=9b²=16c²=25a=3b=4c=5.00
9
16
c² = a² + b²25
c5.000

Adjust aa with the slider, then hit Play. Watch the squares materialize. The two colored squares — one on each leg — always fill exactly as much space as the square on the hypotenuse. Change aa to any value. It always works.

This isn't a coincidence. It's a geometric fact, and it's been proven hundreds of different ways since Euclid. For our purposes, the key point is this: if you know two legs, you can always find the hypotenuse.


Deriving the formula, one step at a time

Now we have everything we need. Let's put it together slowly.

Step through the derivation one piece at a time. Each click reveals the next building block.

A(x₁,y₁)B(x₂,y₂)
Step 1 / 5: Two points on a plane
Start with any two points A and B. We want to find the straight-line distance between them.
Step1 / 5

Work through all five steps. Here's the logic in plain English:

  1. We have two points A=(x1,y1)A = (x_1, y_1) and B=(x2,y2)B = (x_2, y_2).
  2. We draw a right triangle by dropping a corner CC at (x2,y1)(x_2, y_1).
  3. The horizontal leg has length Δx=x2x1\Delta x = |x_2 - x_1|. The vertical leg has length Δy=y2y1\Delta y = |y_2 - y_1|.
  4. By the Pythagorean theorem, the hypotenuse dd satisfies:
d2=Δx2+Δy2d^2 = \Delta x^2 + \Delta y^2
  1. Take the square root of both sides. Distance is always positive, so we drop the absolute value signs:
d=Δx2+Δy2=(x2x1)2+(y2y1)2d = \sqrt{\Delta x^2 + \Delta y^2} = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}

That's it. That's the distance formula.

There's nothing to memorize if you see where it comes from. It's just c=a2+b2c = \sqrt{a^2 + b^2}, where aa is the horizontal gap and bb is the vertical gap.


A few things worth noticing

The order of subtraction doesn't matter. (x2x1)2(x_2 - x_1)^2 and (x1x2)2(x_1 - x_2)^2 are the same — you're squaring, so the negative sign disappears. Distance from A to B equals distance from B to A.

The formula works in any orientation. If the two points are directly horizontal, Δy=0\Delta y = 0 and the formula gives d=Δxd = \Delta x — just the horizontal gap. If they're directly vertical, d=Δyd = \Delta y. The formula handles both special cases without modification.

The formula generalizes to three dimensions, too. For points (x1,y1,z1)(x_1, y_1, z_1) and (x2,y2,z2)(x_2, y_2, z_2):

d=(x2x1)2+(y2y1)2+(z2z1)2d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}

You just add another leg. The triangle becomes a tetrahedron. The logic is identical.


Bonus: the midpoint formula

The distance formula tells you how far apart two points are. But sometimes you want to know the point exactly halfway between them.

That's the midpoint, and it follows directly from the same logic. The midpoint MM between A=(x1,y1)A = (x_1, y_1) and B=(x2,y2)B = (x_2, y_2) is:

M=(x1+x22,  y1+y22)M = \left(\frac{x_1 + x_2}{2},\; \frac{y_1 + y_2}{2}\right)

Just average the coordinates. Why? Because to get halfway in the horizontal direction, you go to the average of x1x_1 and x2x_2. Same vertically. The midpoint is the average of both coordinates simultaneously.

Drag either endpoint. The midpoint M is always the average of both coordinates — and it's always exactly halfway between them.

02244668810103.9053.905M(5, 4.5)A(2,2)B(8,7)
Midpoint x5
Midpoint y4.5
A to M3.905
M to B3.905

Drag either endpoint. The midpoint M chases along, always landing exactly halfway. Notice that the distance from A to M always equals the distance from M to B — they update live in the stat box.

And if you think about it, this is the distance formula in action: both half-distances are equal because M is defined to split the segment exactly.


The short version

Any two points on a plane form the hypotenuse of a hidden right triangle. The legs are the horizontal gap Δx\Delta x and the vertical gap Δy\Delta y. The Pythagorean theorem gives you the hypotenuse — which is the straight-line distance:

d=(x2x1)2+(y2y1)2d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}

You're not memorizing a formula. You're measuring the diagonal of a triangle you can always see.


All visualizations are interactive React components running entirely in your browser. The triangle builder uses drag events mapped to integer grid coordinates. The Pythagorean animation uses requestAnimationFrame with an ease function. No libraries beyond React.