Distance Calculator

Calculate the distance between two points in 2D or 3D space.

Point 1 (x₁, y₁)

Point 2 (x₂, y₂)

Distance
—
Midpoint
—

Quick Examples

Distance Formula

The distance between two points (x₁, y₁) and (x₂, y₂) is:

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

3D Distance

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

Midpoint Formula

M = [(x₁ + x₂)/2, (y₁ + y₂)/2]

What Is the Distance Formula?

The distance formula gives the straight-line length between two points. If you know the coordinates of point A and point B, the formula tells you exactly how far apart they are, as the crow flies. It is one of the most used formulas in mathematics because nearly every field needs to measure separation: navigation systems compute distances between GPS coordinates, video games track how far characters are from objects, and machine learning algorithms measure how similar two data points are.

The formula is a direct application of the Pythagorean theorem. The horizontal and vertical gaps between the two points form the legs of a right triangle, and the straight-line distance is the hypotenuse. Taking the square root of the sum of the squared gaps therefore gives the exact distance. The same idea extends naturally to three dimensions by adding the squared depth gap under the square root.

Distance Formulas in 1D, 2D, and 3D

On a number line, distance is just the absolute difference of the two values. In the plane, the familiar two-dimensional version applies, and in space a third term joins it. The midpoint formula, which finds the point halfway between two others, is a useful companion worth knowing alongside.

1D: d = |x₂ − x₁|
2D: d = √[(x₂ − x₁)² + (y₂ − y₁)²]
3D: d = √[(x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²]
Midpoint: M = ((x₁ + x₂)/2, (y₁ + y₂)/2)

Step-by-Step Calculation

  • Step 1: Write down both points. Here, A = (1, 2) and B = (4, 6).
  • Step 2: Subtract the x-coordinates: 4 − 1 = 3. Subtract the y-coordinates: 6 − 2 = 4.
  • Step 3: Square each difference: 3² = 9 and 4² = 16.
  • Step 4: Add the squares: 9 + 16 = 25.
  • Step 5: Take the square root: √25 = 5. The points are exactly 5 units apart — the classic 3-4-5 right triangle.

Worked Examples

Example 1: Two points in the plane

Find the distance between (1, 2) and (4, 6). The coordinate differences are 3 and 4, so d = √(3² + 4²) = √25 = 5.

d = √(9 + 16) = √25 = 5

Example 2: Three dimensions

Find the distance between (1, 1, 1) and (2, 3, 6). The differences are 1, 2, and 5, so d = √(1² + 2² + 5²) = √(1 + 4 + 25) = √30 ≈ 5.4772.

d = √(1 + 4 + 25) = √30 ≈ 5.4772

Example 3: Midpoint

The midpoint of (1, 2) and (4, 6) is ((1 + 4)/2, (2 + 6)/2) = (2.5, 4). It sits exactly halfway along the segment, 2.5 units from each endpoint.

M = (2.5, 4)

Common Mistakes

  • Subtracting in the wrong order does not matter for distance, but forgetting to square the differences does — signs must disappear before adding.
  • Skipping the final square root and reporting the sum of squares as the distance.
  • Using the 2D formula on 3D points, which silently drops the depth component.
  • Confusing distance with displacement: distance is always non-negative, while displacement keeps a direction.

Frequently Asked Questions

Can distance be negative?

No. The squaring step erases all signs, so the distance formula always returns zero or a positive number. Zero means the two points coincide.

What is the difference between distance and displacement?

Distance is the total straight-line length between two points. Displacement also records direction, so it can be negative along an axis. The distance formula computes the magnitude of the displacement.

What is Manhattan distance?

It is the sum of absolute coordinate differences, |x₂ − x₁| + |y₂ − y₁| — the distance a taxi drives on a street grid. It is longer than the straight-line distance unless the points share a row or column.

Do the units of the coordinates matter?

The distance comes out in the same units as the coordinates. If x and y are in meters, the distance is in meters; mixing units between axes gives a meaningless result.

Three Ways to Measure "Distance"

This calculator computes Euclidean distance — the straight line. Two other measures show up often:

MeasureFormula (2D)When it appliesExample: (1, 2) to (4, 6)
Euclidean√[(x₂−x₁)² + (y₂−y₁)²]Straight-line, as the crow flies√(9 + 16) = 5
Manhattan|x₂−x₁| + |y₂−y₁|City street grids, tile movement in games3 + 4 = 7
Great-circle (Haversine)2R·arcsin(√a)Distances on Earth's curved surfaceNew York to Boston ≈ 306 km

Manhattan distance is always at least as large as Euclidean: a taxi cannot cut through blocks. Great-circle distance accounts for Earth's curvature — flat formulas work fine for a neighborhood, but New York to Boston needs the Haversine version with Earth's radius R = 6,371 km.

Distance from the Origin

A useful special case: the distance from (0, 0) to a point (x, y) is just √(x² + y²). The point (3, 4) sits exactly 5 units from the origin.

Midpoint in 3D

The midpoint formula extends the same way the distance formula does — average each coordinate:

M = ((x₁ + x₂)/2, (y₁ + y₂)/2, (z₁ + z₂)/2)

Example: the midpoint of (1, 1, 1) and (2, 3, 6) is ((1+2)/2, (1+3)/2, (1+6)/2) = (1.5, 2, 3.5).

Where Distance Gets Used

  • Navigation: GPS apps chain millions of distance calculations to find routes.
  • Games and graphics: collision detection checks distances between objects every frame.
  • Construction and surveying: checking diagonals and spans on site.
  • Data science: clustering algorithms group points by how close they are in feature space.
  • Sports fields: laying out a pitch from its corner coordinates.

Quick Checks

  • The distance is never smaller than the largest single coordinate difference.
  • Swapping the two points changes nothing: (1, 2) to (4, 6) is the same 5 units as (4, 6) to (1, 2).
  • For three points, the direct distance never exceeds the sum of the two legs (the triangle inequality).
  • A distance of zero means the points coincide.
>