Distance Between Two Points

Straight-line distance in two or three dimensions, plus midpoint and slope.

Distance

—

  • Change in x—
  • Change in y—
  • Change in z—
  • Midpoint—
  • Slope of the line—
  • Exact form—

How to use this distance calculator

  1. Choose two or three dimensions. Most work is flat, on an x and y grid. Switch to three dimensions for anything with depth.
  2. Enter the coordinates of point A and point B. Negative numbers and decimals are fine.
  3. Read the distance, along with the midpoint and the slope, which are the two things people usually want next.

The working shows the distance formula with your own numbers substituted in, and the exact form keeps the answer as a square root where it does not simplify to a whole number.

The distance formula

The straight-line distance between two points on a plane is:

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

In three dimensions you simply add a third squared term:

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

This is sometimes called Euclidean distance, meaning distance measured in a straight line, as opposed to distance measured along streets, a network or a curved surface.

Why it works

The formula is the Pythagorean theorem wearing different clothes. Draw your two points on a grid, then draw a horizontal line from one and a vertical line from the other. They meet at a right angle, forming a right-angled triangle where the distance you want is the hypotenuse.

The horizontal side has length x₂ − x₁, the vertical side has length y₂ − y₁, and Pythagoras says the hypotenuse squared equals the sum of the other two squared. Take the square root and you have the distance formula. Nothing new is being claimed; it is Pythagoras applied to coordinates.

The subtractions get squared, which is why it does not matter which point you call A and which you call B. A negative difference squares to the same positive number.

A worked example

Find the distance from A(3, 4) to B(9, 12).

  1. Subtract the coordinates. 9 − 3 = 6 across, and 12 − 4 = 8 up.
  2. Square both. 6² = 36 and 8² = 64.
  3. Add them. 36 + 64 = 100.
  4. Take the square root. √100 = 10.

That is a 6-8-10 triangle, which is the familiar 3-4-5 triangle doubled. Most textbook examples are built from these whole-number triples precisely so the answer comes out clean. Real coordinates rarely oblige, which is why the exact form is shown as a square root alongside the decimal.

Distance, midpoint and slope

Three questions get asked about the same pair of points, and all three come from the same two subtractions:

QuantityFormulaWhat it tells you
Distance√(Δx² + Δy²)How far apart they are
Midpoint((x₁+x₂)/2, (y₁+y₂)/2)The point exactly halfway
SlopeΔy / ΔxHow steep the line is

A vertical line has no defined slope, because Δx is zero and dividing by zero has no answer. The distance and midpoint are still perfectly well defined.

Other ways to measure distance

Straight-line distance is one choice among several, and in some fields it is not the natural one:

  • Manhattan distance adds the horizontal and vertical moves instead of taking the hypotenuse: |Δx| + |Δy|. It is the distance a taxi drives on a grid of streets, which is where the name comes from.
  • Chebyshev distance takes the larger of the two, which is how a king moves on a chessboard.
  • Great-circle distance measures across the surface of a sphere, and is what you need for latitude and longitude. Treating the Earth as flat and using the plain distance formula gives noticeably wrong answers over long ranges.
  • Cosine similarity ignores magnitude and compares direction only, which is why it is preferred over Euclidean distance for text embeddings.

Where the distance formula shows up in tech

  • Vector search and embeddings. AI models turn text and images into long lists of numbers, and finding similar items means measuring distance between those vectors. The same formula applies, just with hundreds or thousands of terms under the square root instead of two.
  • Clustering. K-means, the most widely used clustering algorithm, works by repeatedly measuring Euclidean distance from each point to each cluster centre.
  • Game development. Collision detection, enemy aggro ranges and pathfinding all rest on distance between coordinates, usually comparing squared distances to skip the square root entirely for speed.
  • Computer graphics. Lighting falls off with distance from the source, so every lit pixel involves this calculation.
  • Nearest neighbour search. Recommendation systems find the closest items in a feature space, and closest means exactly this.

Frequently asked questions

What is the formula for the distance between two points?

The distance is the square root of ((x2 – x1) squared plus (y2 – y1) squared). In three dimensions, add (z2 – z1) squared inside the square root. It is the Pythagorean theorem applied to coordinates.

How do I find the distance between (3, 4) and (9, 12)?

Subtract to get 6 across and 8 up. Square them for 36 and 64, add to get 100, then take the square root for a distance of 10.

Does it matter which point I call the first one?

No. The differences are squared, so a negative difference squares to the same positive number. Swapping the two points gives an identical distance.

What is Euclidean distance?

Euclidean distance is straight-line distance, measured as the crow flies rather than along a route. It is what the standard distance formula calculates, and it is the default measure in geometry, machine learning and computer graphics.

How do I calculate distance in three dimensions?

Use the same method with one extra term: take the square root of ((x2 – x1) squared plus (y2 – y1) squared plus (z2 – z1) squared). Switch this calculator to three dimensions and the z boxes appear.

What is the difference between distance and displacement?

Distance is how far you actually travelled along your path. Displacement is the straight line from start to finish, with a direction attached. This calculator gives the straight-line separation, which matches the magnitude of the displacement.

Can I use this for latitude and longitude?

Not accurately. The Earth is curved, so distances between map coordinates need the great-circle or haversine formula instead. The flat distance formula is only reliable over short ranges where the curvature does not matter.

Why is the answer sometimes shown as a square root?

Because most distances are irrational numbers that never terminate as decimals. The square root is the exact value, and the decimal beside it is rounded. For example, the distance from (0,0) to (1,1) is exactly the square root of 2, or roughly 1.4142.

Related calculators