Distance Formula Calculator

A free tool by DeepRit, a Google Ads agency that does PPC and nothing else. We build and run Google Ads accounts so every click is accounted for. Book a free audit call

Free distance formula calculator. Find the distance between two points in 2D or 3D, plus the midpoint, with every step of the formula shown.

Midpoint
0
Distance squared
0

Free, no sign-up. Runs in your browser: nothing you type is uploaded or saved.

How to use the distance formula calculator

  1. Enter the first point as x₁ and y₁.
  2. Enter the second point as x₂ and y₂.
  3. For three dimensions, also fill in z₁ and z₂. Leave them blank for a flat, 2D problem.
  4. Read the distance, the midpoint, and the distance squared, with every step of the formula filled in underneath.

Decimals and negative coordinates are fine. The distance formula calculator runs in your browser.

The distance formula

The distance between two points (x₁, y₁) and (x₂, y₂) on a flat plane is:

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

For (1, 2) and (4, 6):

  • x₂ − x₁ = 4 − 1 = 3
  • y₂ − y₁ = 6 − 2 = 4
  • d = √(3² + 4²) = √(9 + 16) = √25 = 5

It doesn't matter which point you call "first", because the differences are squared, so their signs disappear.

Why it works: Pythagoras

Draw a horizontal line from the first point and a vertical line from the second. They meet at a right angle, making a right triangle whose legs are the horizontal and vertical differences (3 and 4 above). The distance between the points is the hypotenuse, and the Pythagorean theorem says the hypotenuse squared equals the sum of the legs squared: 3² + 4² = 5². The distance formula is just the Pythagorean theorem written in coordinates. The Pythagorean theorem calculator solves right triangles directly.

Distance in three dimensions

In 3D, add the third difference:

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

From (0, 0, 0) to (1, 2, 2): √(1 + 4 + 4) = √9 = 3. This is used in physics, 3D graphics, game development, engineering and chemistry (distances between atoms).

The midpoint formula

The calculator also finds the midpoint, the point exactly halfway between the two:

M = ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2)

For (1, 2) and (4, 6), the midpoint is (2.5, 4). In 3D, average the z values too. The midpoint is useful for finding the centre of a line segment, the centre of a circle from the ends of its diameter, or a halfway meeting point on a map grid.

Distance squared

The calculator shows the distance squared as well. Programmers often compare squared distances instead of real distances, because it avoids the square root and gives the same order: if one squared distance is smaller, so is the real distance. This speeds up "find the nearest point" searches in games and maps.

The slope between the points

The distance formula tells you how far apart two points are; the slope tells you the direction and steepness of the line through them: (y₂ − y₁) ÷ (x₂ − x₁). For (1, 2) and (4, 6), the slope is 4 ÷ 3. The slope calculator gives the slope, the line's equation, the angle and the distance together.

Distance on maps

On a flat map with a grid, the distance formula gives the straight-line distance in grid units; multiply by the map scale to get real distance. Two caveats:

  • Latitude and longitude aren't a flat grid. The Earth is curved, and a degree of longitude gets shorter towards the poles. For GPS coordinates, use the great-circle (haversine) formula instead.
  • Straight-line distance isn't travel distance. Roads and paths are longer. In a city grid, "Manhattan distance" (|x₂ − x₁| + |y₂ − y₁|) is often closer to the walking distance.

Other kinds of distance

The formula on this page gives the Euclidean distance, the straight-line distance. Other measures are used in different fields:

  • Manhattan (taxicab) distance: sum of the absolute differences, for grid-based movement.
  • Chebyshev distance: the largest single difference, like a king's moves in chess.
  • Euclidean distance in many dimensions: data science uses the same formula with dozens or hundreds of coordinates to compare data points.

Uses of the distance formula

  • Geometry homework: lengths of sides, checking whether a triangle is isosceles, and perimeter on a coordinate grid. The triangle area calculator finds the area once you have the sides.
  • Circles: the distance from a circle's centre to any point on it is the radius. The circle calculator then gives the area and circumference.
  • Design and layout: distances between elements on a canvas measured in pixels.
  • Games and animation: collision checks and movement.
  • Construction and surveying: distances between points on a site plan.

Common mistakes

  • Subtracting x from y instead of x from x and y from y.
  • Forgetting the square root and giving the squared distance.
  • Adding before squaring: (3 + 4)² is 49, but 3² + 4² is 25.
  • Using the formula on latitude and longitude for long distances.

The distance formula in a spreadsheet

With x₁, y₁, x₂ and y₂ in A1 to D1, use =SQRT((C1-A1)^2+(D1-B1)^2). For many points, fill the formula down. The distance formula calculator is quicker for a single pair and shows each step, which helps with homework.

The distance formula in coordinate geometry problems

Many textbook problems use the distance formula as one step:

  • Is the triangle isosceles? Calculate all three side lengths; if two are equal, it is.
  • Is it a right triangle? Check whether the squared lengths satisfy a² + b² = c².
  • Find the perimeter of a shape on a grid by adding the distances between its vertices.
  • Find the radius of a circle from its centre and a point on it.
  • Find a point equidistant from two others using the midpoint and slope.

The distance formula calculator shows each step, so it's useful for checking working as well as answers.

Distance between points on a map grid

On a flat grid map, such as a floor plan or a game map, the distance formula gives the straight-line distance in grid units. Multiply by the scale to get real distance: if each grid square is 2 metres and the distance is 5 squares, the real distance is 10 metres. For distances on the Earth's surface using latitude and longitude, the curvature matters, so use a great-circle formula instead.

Distance in data and machine learning

The same formula, extended to many dimensions, is used to measure how similar two data points are. In a recommendation system, each product or user might be described by dozens of numbers; the Euclidean distance between them shows how alike they are. Clustering algorithms, nearest-neighbour searches and many other techniques rely on it. The distance formula calculator handles two and three dimensions; the principle is the same for more.

Checking your work

A quick way to check a distance calculation is to estimate it first. If the points differ by 3 in x and 4 in y, the distance must be more than 4 (the larger difference) and less than 7 (the sum of the differences). The distance formula calculator's answer of 5 fits. Estimating catches mistakes like forgetting the square root.

Quick tips

  • Subtract x from x and y from y.
  • Square before adding.
  • Take the square root at the end.

Who uses a distance formula calculator

Maths students use it for coordinate geometry homework and exam preparation. Teachers use it to create and check worked examples. Game developers and designers use it to measure distances between objects on screen. Engineers and drafters use it to check lengths on plans, and data analysts use the same idea to measure how similar two data points are. The formula is simple, but seeing every step helps avoid small mistakes.

A worked example

A student is checking a geometry worksheet. Point A is at (1, 2) and point B at (4, 6). She enters the coordinates into the distance formula calculator: the distance is 5, the midpoint is (2.5, 4), and the distance squared is 25. The working reads √(3² + 4²) = √25 = 5.

A game developer uses the same tool to check a 3D calculation: the distance from (0, 0, 0) to (1, 2, 2) is 3, and the midpoint is (0.5, 1, 1).

Need more customers from Google?

This tool is free and runs in your browser. If your business also needs more leads or sales, Google Ads is where people search with their wallet out. DeepRit manages Google Ads for small and mid-size businesses, and only Google Ads. We check your account before we ever get on a call, then fix the structure, the keywords, the tracking and the ads, with month-to-month terms and no long contract. Book a free audit call.

Sources and further reading

  • Euclidean distance on Wikipedia: the distance formula in two, three and more dimensions.

Frequently asked questions

What is the distance formula?

d = √((x₂ − x₁)² + (y₂ − y₁)²). The distance formula calculator applies it to any two points.

How do you find the distance between two points?

Subtract the x values and the y values, square both differences, add them, and take the square root.

How do you find the distance in 3D?

Add the squared difference in z: d = √(Δx² + Δy² + Δz²).

What is the midpoint formula?

The average of the coordinates: ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2).

Can I use the distance formula with GPS coordinates?

Not accurately over long distances, because the Earth is curved. Use the haversine formula instead.

Is the distance formula calculator free?

Yes. It's free, needs no sign-up, and works in your browser.

Free PPC audit

See where your ad budget leaks.

We look at your Google Ads account before the call, then walk you through what we'd fix first, in dollars. No obligation, no hard sell.

Book a free audit call 30-minute call · Free · The audit is yours to keep