Math Tools Math Tools

How to Calculate the Distance Between Two Points

How to Calculate the Distance Between Two Points

By Math Tools ·

How to Calculate the Distance Between Two Points

In Manhattan, you can't walk diagonally through buildings. To get from one intersection to another 6 blocks east and 8 blocks north, you have to walk 14 blocks. A crow flying straight there covers only 10 blocks.

Both are valid "distances," and mathematicians use both. The straight-line version comes from one of the most famous formulas in mathematics, and it's the one you'll use most. Here's how to calculate it, and when to use the alternatives.


The Distance Formula Is the Pythagorean Theorem in Disguise

The distance formula looks like something new to memorize. It isn't. Draw a horizontal line and a vertical line connecting two points, and you've made a right triangle. The distance between the points is the hypotenuse. That's all the formula is.


The Formula (2D)

For points (x₁, y₁) and (x₂, y₂):

d = √((x₂ − x₁)² + (y₂ − y₁)²)

The horizontal leg is (x₂ − x₁), the vertical leg is (y₂ − y₁), and the Pythagorean theorem, a² + b² = c², gives the hypotenuse. See the analytic geometry formulas.


Example 1: Positive Coordinates

Find the distance between (1, 2) and (7, 10).

Step 1: Find the differences.

x₂ − x₁ = 7 − 1 = 6
y₂ − y₁ = 10 − 2 = 8

Step 2: Square them.

6² = 36
8² = 64

Step 3: Add and take the square root.

d = √(36 + 64) = √100 = 10

Distance = 10 units. It's the classic 6-8-10 right triangle. Check with the right triangle calculator.


Example 2: Negative Coordinates

Find the distance between (−3, 4) and (5, −2).

x₂ − x₁ = 5 − (−3) = 8
y₂ − y₁ = −2 − 4 = −6
d = √(8² + (−6)²) = √(64 + 36) = √100 = 10

Squaring removes negative signs, so the order of the points doesn't matter. Be careful subtracting negatives: 5 − (−3) is 8, not 2.


Example 3: A Non-Perfect Result

Distance between (2, 3) and (5, 7):

d = √(3² + 4²) = √25 = 5

Distance between (0, 0) and (3, 5):

d = √(9 + 25) = √34 ≈ 5.831

Look up roots in the square roots list.


The Formula in 3D

Add a third term for the z-coordinate:

d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)

Example: From (1, 2, 3) to (4, 6, 15):

d = √(3² + 4² + 12²) = √(9 + 16 + 144) = √169 = 13

The same pattern extends to any number of dimensions, which is how machine learning measures distances between data points with hundreds of features.


Other Kinds of Distance

Manhattan (Taxicab) Distance

When movement is restricted to a grid, add the absolute differences:

d = |x₂ − x₁| + |y₂ − y₁|

From (1, 2) to (7, 10): |6| + |8| = 14, the city-block walk from the introduction. It's used in city routing, some machine learning algorithms and warehouse robotics.

Great-Circle Distance on Earth

GPS coordinates sit on a sphere, so a flat formula isn't accurate over long distances. Navigation software uses the haversine formula:

a = sin²(Δφ/2) + cos φ₁ cos φ₂ sin²(Δλ/2)
d = 2R × arcsin(√a)

where φ is latitude, λ is longitude (in radians) and R ≈ 6,371 km. From New York to London, it gives about 5,570 km. Convert angles with degrees to radians, and see The Math Behind Google Maps.


An Insider Reference: Descartes, Fermat and the Coordinate Plane

The distance formula depends on describing points with coordinates, an idea we now take for granted. It was developed independently in the 1630s by two French mathematicians.

René Descartes published La Géométrie in 1637, as an appendix to his famous Discourse on the Method, showing how geometric problems could be translated into algebra. Pierre de Fermat had developed similar ideas around the same time in work that circulated in manuscript. Their combined insight, now called analytic geometry, is why the grid is known as the Cartesian plane. It turned the ancient Pythagorean theorem into a formula anyone could apply to coordinates.


Two Concepts Worth Knowing

Midpoint

The midpoint between two points averages their coordinates: ((x₁ + x₂)/2, (y₁ + y₂)/2). For (1, 2) and (7, 10), it's (4, 6).

Metric

A metric is any rule for measuring distance that satisfies a few properties, like never being negative and obeying the triangle inequality. Straight-line, Manhattan and great-circle distances are all metrics.


Quick Answer: How Do You Find the Distance Between Two Points?

Use the distance formula d = √((x₂ − x₁)² + (y₂ − y₁)²): subtract the coordinates, square the differences, add them and take the square root. For (1, 2) and (7, 10), d = √(6² + 8²) = √100 = 10. In 3D, add (z₂ − z₁)² under the square root.


Try Them Yourself

Pick two locations on a city map with a grid, estimate their coordinates, and calculate both the straight-line and Manhattan distances. The gap between them is the price of not being able to walk through buildings.