Distance Formula Calculator

Find the straight-line distance between two points.

Distance Formula Calculator tool

Dimensions
—
Distance
—
Differences
—
Midpoint

About the Distance Formula Calculator

Finding the straight-line distance between two points is a staple of coordinate geometry, game programming and mapping. This distance formula calculator applies the Pythagorean theorem to the differences in coordinates, in two or three dimensions, and shows the exact square root alongside the decimal: from (1, 2) to (4, 6) the distance is exactly 5.

In two dimensions, d = √((x₂ − x₁)² + (y₂ − y₁)²). In three dimensions a third term is added for the z-coordinates: d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²). The order of the points does not matter, because the differences are squared. The calculator also gives the midpoint of the segment, which sits halfway along each coordinate.

Example: from (1, 2) to (4, 6), the differences are 3 and 4, so d = √(9 + 16) = √25 = 5. From (0, 0) to (2, 6), d = √40 = 2√10 ≈ 6.3246. In 3D, from (1, 2, 3) to (4, 6, 15) the differences are 3, 4 and 12, so d = √(9 + 16 + 144) = √169 = 13. These are lengths in whatever unit the coordinates use.

On a map the distance formula only works for small areas with flat coordinates; distances on the globe need great-circle methods. For the slope and equation of the line through two points, see the slope calculator; for the halfway point, the midpoint calculator; and for right triangles, the Pythagorean theorem calculator.

How to use the Distance Formula Calculator

  1. Choose 2D or 3DPick two coordinates per point, or three.
  2. Enter the first pointType x₁, y₁ and, in 3D, z₁.
  3. Enter the second pointType x₂, y₂ and, in 3D, z₂.
  4. Read the distanceSee the decimal distance, the exact root and every step.

Distance Formula Calculator features

  • 2D and 3D distance
  • Exact simplified square roots
  • Differences along each axis
  • Midpoint of the segment
  • Step-by-step formula
  • Negative and decimal coordinates
  • Instant, private and free

Common uses

  • Coordinate geometry homework
  • Game development and graphics
  • Lengths in CAD and design drawings
  • Physics displacement problems
  • Checking map grid distances

The distance formula in practice: games, maps, data and choosing a distance

By the FreeToolsWorld editorial team · Updated November 2026 · How we write and check our guides

The distance formula finds the straight-line distance between two points from their coordinates. It is Pythagoras' theorem written for a coordinate grid, and it powers games, mapping, robotics and data analysis. This guide covers practical uses, a worked game example, a fast trick programmers use to avoid square roots, map grids measured in metres and other ways of measuring distance that suit different problems.

Games and simulations

Video games constantly check distances: whether an enemy is close enough to attack, whether a player has reached a checkpoint, or which item is nearest. Each check uses the distance formula on the objects' coordinates. Physics engines, animation systems and collision detection rely on it many times per frame.

A worked example: a range check

A player stands at (3, 4) and an enemy at (11, 10). The differences in the coordinates are 8 and 6, so the distance is the square root of 8² + 6², which is the square root of 100, exactly 10 units. If the enemy can attack within 12 units, the player is in range.

Comparing squared distances

Programmers often skip the square root when they only need to compare distances, because the square root is slower to compute and does not change which distance is larger. In the example above, instead of comparing 10 with 12, compare 100 with 144. When thousands of distance checks run every second, this simple trick saves noticeable time.

Map grids in metres

Many maps use projected grids, such as the UTM system, where coordinates are in metres east and north of a reference point. On such grids, the distance formula gives real distances directly over short to moderate ranges. For latitude and longitude, which are angles on a curved Earth, the haversine formula is needed instead, because degrees of longitude shrink towards the poles.

Data and nearest neighbours

In data analysis, each item can be a point in a space with many dimensions, such as height, weight and age for people, or many features for products. The distance between points measures similarity. Recommendation systems and classification methods such as k-nearest neighbours find the items closest to a new one. Because features use different units, data is usually scaled first so that no single feature dominates the distance.

Other kinds of distance

Straight-line distance is not always the right measure. In a city with a grid of streets, the Manhattan distance, the sum of the horizontal and vertical differences, matches how far you actually walk. On a chessboard, a king's moves follow the Chebyshev distance, the larger of the two differences. Choosing the distance that matches how movement really happens gives more meaningful answers.

Three dimensions

The formula extends to three dimensions by adding the squared difference in the third coordinate. Engineers use the 3D version for the length of a cable between two points at different heights, and 3D printers and CNC machines use it to plan the paths their tools travel.

Precision and exact forms

When coordinates are whole numbers, the distance may be an exact whole number, as in the example above, or a square root such as √50, which simplifies to 5√2. Exact forms are preferred in algebra and geometry classes, while decimals suit practical measurements.

Common mistakes

  • Forgetting to square the differences before adding.
  • Using latitude and longitude directly in the formula.
  • Comparing distances in mixed units or unscaled data.
  • Using straight-line distance where movement follows a grid.

Related tools

For midpoints, use Midpoint Calculator. For slopes between points, try Slope Calculator, and for right triangles, Pythagorean Theorem Calculator.

Distances in spreadsheets

In a spreadsheet, the distance between two points with coordinates in columns A to D is =SQRT((C2-A2)^2+(D2-B2)^2). Filling the formula down a column gives distances for a whole list of pairs, such as delivery points from a depot on a local grid. Remember that spreadsheet distances on latitude and longitude are not real distances; use a grid in metres or a spherical formula for those.

Directions and unit vectors

In games and simulations, the distance formula also helps work out directions. Dividing the differences in the coordinates by the distance gives a unit vector, a direction with length 1, which can be multiplied by a speed to move an object towards a target at a steady pace. Without this step, objects would move faster when far away and slower when close.

When circles touch

Two circles overlap when the distance between their centres is less than the sum of their radii. Games use this as a quick collision test for round objects, and engineers use the same idea to check clearances between round parts. Comparing squared values, distance squared against the square of the radii sum, avoids square roots again.

Limits

Results are exact for the coordinates entered; geographic distances need a spherical formula rather than this flat-grid calculation.

Frequently asked questions

What is the distance formula?

d = √((x₂ − x₁)² + (y₂ − y₁)²). Subtract the x-coordinates and the y-coordinates, square both differences, add them and take the square root. For (1, 2) and (4, 6) this gives √(9 + 16) = 5.

How is the distance formula related to Pythagoras?

The differences in x and y are the legs of a right triangle whose hypotenuse joins the two points. The distance formula is just a² + b² = c² written with coordinates.

How do I find the distance in 3D?

Add a third squared difference for z: d = √(Δx² + Δy² + Δz²). From (0, 0, 0) to (1, 2, 2), d = √(1 + 4 + 4) = 3. The same idea extends to any number of dimensions.

Does the order of the points matter?

No. Swapping the points changes the sign of each difference, but squaring removes the sign, so the distance is the same either way. (x₁ − x₂)² is always equal to (x₂ − x₁)².

Can the distance be negative?

No. A distance is a square root of a sum of squares, so it is always zero or positive. It is zero only when the two points are the same.

How do I leave the answer in exact form?

Simplify the square root by taking out square factors. √40 = √(4 × 10) = 2√10. The calculator shows this whenever the coordinates are whole numbers. Teachers often prefer this form because it involves no rounding.

Can I use the distance formula for GPS coordinates?

Only roughly, over short distances, because latitude and longitude are angles on a curved surface. For real travel distances use a great-circle formula such as the haversine formula.

What is the distance from a point to the origin?

Use (0, 0) as the other point, so the formula becomes d = √(x² + y²). The point (5, 12) is √(25 + 144) = √169 = 13 units from the origin.

What is Manhattan distance?

The distance traveled along a grid, adding the horizontal and vertical differences instead of using the straight line: |Δx| + |Δy|. From (1, 2) to (4, 6) it is 3 + 4 = 7, compared with a straight-line distance of 5.