Home › Distance Formula Calculator

Distance Formula Calculator

Enter two points — in 2D or 3D — and get the straight-line distance between them, with every step of the working written out so you can follow, check or copy the method.

How to Use This Calculator

  1. Choose the dimensions from the first control: 2D for points with two coordinates, written (x, y), or 3D for points with three, written (x, y, z). Switching to 3D reveals the two extra boxes for the z coordinates.
  2. Enter point 1 — its x value in the x₁ box and its y value in the y₁ box. Negative values are welcome; points are not required to sit in the positive corner of the grid.
  3. Enter point 2 in the x₂ and y₂ boxes in the same way. Keep each coordinate with its own axis: x with x, y with y, and z with z if you are working in 3D.
  4. Press "Calculate with steps". The tool shows the distance itself and, underneath it, a step panel that prints every stage of the working — the differences, their squares, the sum and the square root — for the exact numbers you entered.
  5. Read the steps, not just the answer. If you are learning the method, compare each line of the step panel with your own written working; where they differ is where the lesson is.

A worked example, right up front

Enter point 1 as (1, 2) and point 2 as (4, 6). The difference in x is 4 − 1 = 3, and the difference in y is 6 − 2 = 4. Square each difference: 3² = 9 and 4² = 16. Add the squares: 9 + 16 = 25. Take the square root: √25 = 5. The two points are exactly 5 units apart — no rounding, no approximation. A second pair confirms the pattern at a larger scale: point 1 (2, 3) and point 2 (7, 15) give differences of 5 and 12, squares of 25 and 144, a sum of 169, and a distance of exactly 13. Both examples belong to the famous family of whole-number right-angled triangles, which is precisely why teachers reach for them: the method and the answer can both be checked at a glance. Type either pair into the tool above and the step panel will reproduce this working line by line.

Worked examples, step by step

Try (−2, 1) and (4, −3). The differences are Δx = 4 − (−2) = 6 and Δy = −3 − 1 = −4. Squaring gives 36 and 16 — note that the negative sign disappears, which is why the formula works in every direction, not just up and to the right. Adding gives 52, and √52 ≈ 7.21. So the two points are about 7.21 units apart, even though one of the differences was negative and one point sits in a different quadrant from the other.

Now a 3D example: from (1, 2, 3) to (4, 6, 3). The differences are Δx = 3, Δy = 4 and Δz = 0, so d = √(9 + 16 + 0) = √25 = 5. The zero in z means both points lie at the same height, and the answer is the familiar 3-4-5 result. Change the second point to (4, 6, 15) and Δz becomes 12: now d = √(9 + 16 + 144) = √169 = 13 — a neat 5-12-13 triangle stretched through space. Examples like these are worth trying in the tool above, because the step panel shows exactly where each number in the working comes from.

What Is the Distance Between Two Points?

The distance between two points is the length of the straight line segment that joins them — the shortest path across the grid, cutting directly from one point to the other rather than travelling along the grid lines. It is a single positive number, measured in whatever units the grid uses: centimetres on graph paper, pixels on a screen, metres on a floor plan, or abstract "units" in a maths exercise. It has no direction. The distance from A to B is exactly the distance from B to A, and the formula is built to guarantee that, because squaring each difference erases whether it was positive or negative.

It helps to separate this idea from the distance you would walk or drive between the same points. On a street grid, a person might have to travel the horizontal difference and then the vertical difference, one after the other — a longer journey than the straight segment, because the diagonal is closed to them. The distance formula always answers the diagonal question: how far apart the points are, as the crow flies across the grid. Knowing which of those two questions you are being asked — the direct gap or the along-the-lines journey — is half of using the formula well.

Why the flat formula fails on latitude and longitude

It is tempting to treat a pair of latitude and longitude values as if they were x and y on graph paper, subtract them, square, add and take the root. The result would be meaningless, and understanding why protects you from a very common real-world error. Latitude and longitude are not lengths; they are angles, measured in degrees from the centre of the Earth. A degree of latitude covers roughly the same ground distance everywhere, but a degree of longitude covers a wide span at the equator and shrinks steadily towards the poles, where all the longitude lines meet and the ground distance falls to nothing. A flat subtraction cannot know any of that: it treats one degree as one unit in both directions, everywhere on the planet, which is only ever true by accident.

The scale of the mistake is easy to see with two real cities. New York, at latitude 40.7128 and longitude −74.0060, and Los Angeles, at latitude 34.0522 and longitude −118.2437, differ by about 6.66 degrees of latitude and about 44.24 degrees of longitude. Fed raw into the flat formula, those degree differences produce a number in "degrees" that corresponds to no real distance at all. The correct method works on the sphere itself, and it gives a straight-line distance of 2,445.6 miles between the two cities. That spherical method is the haversine formula, shown below — and it is the method our main distance calculator applies when you use its GPS mode, as the as the crow flies guide explains.

Common mistakes to avoid

The most frequent error is adding the differences before squaring — computing √(Δx + Δy) instead of √(Δx² + Δy²). The squares must come first, always. A second classic is forgetting the final square root, which leaves you with the distance squared: an answer of 25 for the (0, 0) to (3, 4) problem instead of 5. A third is mixing up the pairing — subtracting x₁ from y₂, for instance. Each difference must stay within its own axis: x with x, y with y, z with z. Finally, watch out for negative coordinates: subtracting a negative adds, so from −2 to 4 is a difference of 6, not 2. If a hand answer and the calculator disagree, re-check these four points in order; one of them is almost always the culprit. Our Euclidean distance guide works through the same pitfalls with diagrams described in words.

How Does This Calculator Work?

  1. It reads the coordinates of both points, in 2D or 3D according to the Dimensions control.
  2. It subtracts the coordinates axis by axis: x₂ minus x₁, y₂ minus y₁, and z₂ minus z₁ in 3D.
  3. It squares each difference, which makes every term positive and matches the sides of the right-angled triangle the formula is built on.
  4. It adds the squared differences together.
  5. It takes the square root of the sum — that root is the distance.
  6. It prints each of those stages in the step panel, so the working can be followed, checked or copied.

What Formula Does It Use?

The distance formula is Pythagoras' theorem wearing a coordinate grid. Draw a right-angled triangle between two points: the horizontal side is the difference in x (Δx), the vertical side is the difference in y (Δy), and the distance you want is the hypotenuse. Pythagoras says the hypotenuse squared equals Δx² + Δy², so the distance is d = √((x₂−x₁)² + (y₂−y₁)²). The classic example is already filled in above: from (0, 0) to (3, 4) the differences are 3 and 4, the squares are 9 and 16, the sum is 25, and the distance is exactly 5 — the famous 3-4-5 triangle.

The 3D version adds one more term, because space has one more direction to differ in: d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²). Nothing else changes — subtract, square, add, square-root. That four-step rhythm is exactly what the step panel above prints for your numbers, which is why this tool is popular for homework: it shows the method your teacher wants to see, not just the answer.

Notice what this formula assumes: a flat grid where x and y mean the same thing everywhere. That is true for graph paper, floor plans, game worlds and screen pixels — but not for latitude and longitude on the real Earth, where the grid itself curves. For real places, use the main distance calculator, which uses the haversine formula on a sphere instead; the as the crow flies guide explains the difference. A handy bridge between the two worlds: near any given town, one degree of latitude is about 69 miles everywhere, while a degree of longitude shrinks from 69 miles at the equator towards zero at the poles.

The 2D distance formula

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

In simple words: measure how far apart the two points are sideways and how far apart they are up-and-down, square both gaps, add them, and take the square root — that root is the straight-line gap between the points.

where:

Worked through with the example from the top of this page, point 1 (1, 2) and point 2 (4, 6):

  1. Step 1 — find the differences: x₂ − x₁ = 4 − 1 = 3, and y₂ − y₁ = 6 − 2 = 4.
  2. Step 2 — square each difference: 3² = 9, and 4² = 16.
  3. Step 3 — add the squares: 9 + 16 = 25.
  4. Step 4 — take the square root: d = √25 = 5.

A second pair runs through the identical steps: point 1 (2, 3) and point 2 (7, 15) give differences of 7 − 2 = 5 and 15 − 3 = 12, squares of 25 and 144, a sum of 169, and d = √169 = 13.

The 3D distance formula

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

In simple words: do exactly what the 2D formula does, but measure the gap in the third direction too — how far apart the points are in height or depth — square it and add it in before the square root.

where:

Worked through with point 1 (1, 2, 3) and point 2 (4, 6, 15):

  1. Step 1 — find the differences: x: 4 − 1 = 3; y: 6 − 2 = 4; z: 15 − 3 = 12.
  2. Step 2 — square each difference: 3² = 9, 4² = 16, and 12² = 144.
  3. Step 3 — add the squares: 9 + 16 + 144 = 169.
  4. Step 4 — take the square root: d = √169 = 13.

The haversine formula — the spherical counterpart for real places

a = sin²(Δφ/2) + cos φ₁ · cos φ₂ · sin²(Δλ/2);   c = 2 · atan2(√a, √(1 − a));   d = R · c

In simple words: instead of pretending the Earth is flat graph paper, this chain of steps measures the angle between two places as seen from the centre of the Earth, then multiplies that angle by the Earth's radius to get the real distance across the surface.

where:

Worked through with New York (latitude 40.7128, longitude −74.0060) and Los Angeles (latitude 34.0522, longitude −118.2437), using R = 3,958.8 miles:

  1. Step 1 — change the latitudes to radians: φ₁ = 0.7106 and φ₂ = 0.5943. The differences are Δφ = −0.1162 radians and Δλ = −0.7721 radians (the signs will disappear when the values are squared).
  2. Step 2 — work out the two squared sine terms: sin²(Δφ/2) ≈ 0.0034, and sin²(Δλ/2) ≈ 0.1418.
  3. Step 3 — add in the latitude cosines: cos φ₁ ≈ 0.7580 and cos φ₂ ≈ 0.8285, so a ≈ 0.0034 + (0.7580 × 0.8285 × 0.1418) ≈ 0.0924.
  4. Step 4 — turn a into the centre angle: c = 2 · atan2(√0.0924, √(1 − 0.0924)) ≈ 0.6178 radians.
  5. Step 5 — multiply by the Earth's radius: d = 3,958.8 × 0.6178 ≈ 2,445.6 miles — the great-circle distance between the two cities.

Note: the two formulas are not rivals. The first is exact on a flat grid; the second is the right tool on a sphere. Choosing between them is simply a matter of knowing which surface your points live on — our haversine formula page and Euclidean distance guide each treat one side of that choice in depth.

Euclidean Distance Compared With Manhattan Distance

The distance on this page is called Euclidean distance, after the geometry of the flat plane, and it has several near neighbours worth telling apart. Manhattan distance adds the absolute differences instead of squaring them — |x₂ − x₁| + |y₂ − y₁| — and measures the journey along grid lines, like a taxi crossing a city of rectangular blocks; it is always at least as long as the Euclidean distance between the same points.

Euclidean Distance Compared With Haversine Distance

Haversine distance, shown above, is the spherical answer for latitude and longitude on the Earth.

Euclidean Distance Compared With Driving Distance

Driving distance is longer still in most cases, because roads follow terrain, junctions and one-way systems rather than either geometry.

Euclidean Distance Compared With a Single-Axis Difference

And the plain difference in one axis — just Δx, say — is not a distance between points at all, only a separation along one direction. Matching the measure to the question is the real skill: the diagonal for the gap, Manhattan for the grid journey, haversine for the globe, and a routing tool such as the driving distance calculator for the road.

Edge Cases Worth Knowing About

Several special inputs test whether you understand the formula, and the calculator handles each of them in the mathematically honest way.

What if both points are the same?

Enter the same point twice and every difference is zero, so the distance is zero — correct, because a point is no distance from itself.

What if a difference comes out negative?

Negative coordinate differences cause no trouble at all: if x₂ is smaller than x₁, the difference is negative, but squaring turns it positive before anything is added, which is why the formula works in every direction and every quadrant, and why swapping the two points changes nothing.

What if you have to subtract a negative number?

Watch one trap inside that rule, though: subtracting a negative adds. The gap between −2 and 4 on one axis is 6, not 2, and hand calculations most often go wrong exactly there.

What if the points share one coordinate?

Vertical and horizontal pairs are the friendliest case: when one difference is zero, the distance is simply the other difference — the formula reduces to measuring along a straight line. Finally, in 3D, points that share the same z behave exactly like a 2D problem, because the z term contributes zero to the sum under the root.

Practical uses for the distance formula

School and university coursework

This is the formula's home ground: coordinate geometry exercises, Pythagoras problems and the first steps into vectors all reduce to subtract, square, add, root. The step panel above exists for this use — it shows the layout examiners expect, with your numbers in it.

Games, graphics and screen coordinates

Pixels are points on a flat grid, so game and interface code asks Euclidean questions constantly: how far is the character from the door, which enemy is nearest, did the click land within the circle? The circle radius calculator is a close cousin for the round-boundary version of those questions.

Plans, layouts and measured drawings

On a floor plan or site drawing, coordinates locate corners, sockets and furniture, and the formula turns two plotted positions into the real diagonal between them — the length of a cable run, a worktop cut on the bias, or a sight line across a room — without anyone climbing a ladder with a tape.

Data and spreadsheets

Any table with two numeric columns can be treated as points: measurements before and after, predicted against actual, one product's price and rating against another's. Euclidean distance then measures how far apart two rows are overall, which is the seed of clustering, nearest-neighbour searches and much of everyday data analysis.

Accuracy and limits, stated honestly

On a true flat grid the formula is exact, and the only inaccuracy available is in the numbers you feed it: coordinates rounded early, measurements taken loosely, or a grid whose two axes secretly use different units — centimetres across and inches up, say — which corrupts the result while looking perfectly respectable. The deeper limit is the flatness assumption itself. The formula describes a plane, so it is the wrong instrument wherever the surface curves: on the Earth beyond very short local spans, on a globe, or in any setting where latitude and longitude are involved, where the haversine method belongs instead. It also measures the direct gap only. It knows nothing of obstacles, walls, roads or terrain between the points, so a Euclidean answer can be exactly right as geometry and still useless as a journey — for journeys, a routing tool such as the map distance calculator answers the question you actually meant to ask.

What each part of the result means

The calculator returns two things. The distance itself is a single number in the grid's units — the length of the straight segment joining your points. If it arrives as a whole number, your points form one of the neat Pythagorean patterns; if it arrives as a long decimal, that is normal, and rounding to two decimal places is standard practice for coursework and practical use alike. The step panel underneath is the audit trail: the differences on each axis, each difference squared, the sum of the squares, and finally the square root. Reading it top to bottom is the fastest way to catch an input slip — a mistyped coordinate shows up immediately as a difference that is not the one you expected, long before it can poison the final answer. If the panel shows a z line, you are in 3D mode; if it does not, the calculation was two-dimensional.

When to use this tool — and when to use a different one

Use this calculator whenever your points live on a flat grid: maths homework, floor plans, board and video game positions, screen or image coordinates, spreadsheet data, and any x-y plot. The moment your “points” are real places on Earth, switch tools. Latitude and longitude are angles on a sphere, not flat-grid coordinates, so the right instrument is the main distance calculator, whose GPS mode applies the haversine formula. If your two points are street addresses rather than numbers, the distance between addresses tool geocodes them first and then does the spherical maths for you. And if you need the point exactly halfway between two coordinate pairs — on a grid or on the globe — the midpoint calculator handles both. Knowing which geometry you are in is half the problem; the formulas themselves are the easy half.

Frequently asked questions

What is the distance between (0, 0) and (3, 4)?

Exactly 5 units. The difference in x is 3 − 0 = 3 and the difference in y is 4 − 0 = 4, so the squares are 9 and 16. Adding them gives 25, and the square root of 25 is 5. It is the best-known Pythagorean triple — three whole numbers that fit Pythagoras' theorem exactly — which is why this pair of points appears in almost every textbook introduction to the formula.

Does the order of the points matter?

No — point 1 to point 2 gives exactly the same distance as point 2 to point 1. Swapping the points only flips the sign of each difference: (1, 2) to (4, 6) gives differences of 3 and 4, while the reverse gives −3 and −4. Squaring removes those signs, turning both into 9 and 16, so the sum and the square root are identical either way. Distance has no direction, and the formula is built to guarantee that.

Can I use this for latitude and longitude?

Not properly — only as a rough approximation over very short local spans. Latitude and longitude are angles in degrees, not lengths on a flat grid, and a degree of longitude covers a wide span of ground at the equator but shrinks towards nothing at the poles, which a flat subtraction cannot know about. For real places, use the main calculator's GPS mode, which applies the haversine formula on a sphere instead. That is the method that gives the true 2,445.6-mile great-circle distance between New York and Los Angeles quoted on this page.

What is the distance formula in 3D?

It is the 2D formula with one extra squared difference for the third axis: d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²). The method is unchanged — subtract on each axis, square, add, and take the root. For example, (1, 2, 3) to (4, 6, 15) gives differences of 3, 4 and 12, squares of 9, 16 and 144, a sum of 169, and a distance of exactly 13. Switch the Dimensions control above to 3D and the tool shows this working for your own numbers.

Why do teachers want the steps, not just the answer?

Because the method is the skill being taught, and the answer alone proves nothing about how it was reached. The expected layout is always the same rhythm: subtract to get the differences, square each one, add the squares, then take the square root. Showing those steps lets a teacher see exactly where a wrong answer went wrong — a skipped square root, say, rather than a slip in the final figure. The step panel above prints that working for your numbers, so you can copy the layout and substitute your own values in classwork.

What is a Pythagorean triple, and why do the examples keep using them?

A Pythagorean triple is a set of three whole numbers that fit Pythagoras' theorem exactly, such as 3-4-5, 5-12-13 and 8-15-17. Teachers reach for them because the distance comes out as a whole number — √(9 + 16) is exactly 5, with no rounding anywhere. That keeps the focus on the method instead of on wrestling with decimals, and it makes answers easy to check at a glance. Real-world coordinates rarely land on a triple, so most practical answers are decimals, and that is entirely normal.

Can the distance between two points ever be negative?

No. Each difference is squared before anything is added, and a square is always positive or zero, so the sum under the root can never be negative. The square root of that sum is therefore never negative either. The smallest possible distance is zero, and that happens only when the two points are the same point, so every difference is zero. If a hand calculation produces a negative distance, a sign has gone wrong somewhere in the subtraction stage.

What is the distance between (1, 2) and (4, 6)?

Exactly 5 units. The difference in x is 4 − 1 = 3 and the difference in y is 6 − 2 = 4. Squaring gives 9 and 16, adding gives 25, and the square root of 25 is 5. It is the 3-4-5 triangle shifted away from the origin, which is a useful reminder that the formula cares only about the gaps between the points, not about where on the grid the pair happens to sit.

How is Euclidean distance different from Manhattan distance?

Euclidean distance is the straight diagonal between two points — the route a bird could take across the grid. Manhattan distance instead adds the absolute horizontal and vertical differences, measuring a journey forced to travel along the grid lines, like a taxi crossing a city of rectangular blocks. Between (1, 2) and (4, 6), the Euclidean distance is 5 while the Manhattan distance is 3 + 4 = 7. Between any two points, Manhattan distance is always equal to or greater than Euclidean distance, and the two agree only when the points share a row or a column.

Do the units of x and y have to match?

Yes — both axes must use the same unit, or the squares mix incompatible quantities and the result is meaningless. If one axis is in centimetres and the other in metres, convert one of them before calculating: a gap of 3 metres across and 400 centimetres up is really 3 and 4 in the same unit, giving a distance of 5. The same rule applies inside spreadsheets and floor plans, where mixed units are the most common quiet cause of a wrong answer. When in doubt, convert everything to the smaller unit first, calculate, then convert back.

Which tool should I use for the distance between two real places?

Use the main distance calculator for the straight-line distance between places, since it applies the spherical haversine maths that latitude and longitude need. The air miles calculator suits flight-style distances, and the driving distance calculator answers the different question of the road route between two places. This page's formula is for points on a flat grid — graph paper, screens, floor plans and game worlds. Choosing by the surface your points live on is the whole decision.