# How do I use the distance formula?

Finds the distance between two points in 2D or 3D with the distance formula, as an exact square root and a decimal, with each step of the working.

- Page: https://www.acalculator.org/math/distance-formula-calculator
- JSON spec: https://www.acalculator.org/math/distance-formula-calculator.json
- Version: 3cad7127c9c0

## Default answer

Example with the default inputs (Points in 2D (x, y), x₁ 1, y₁ 2, x₂ 4, y₂ 6): The distance between the two points is 5.

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| dim | Points in | Points on a plane (x, y) or in space (x, y, z). |
| x1 | x₁ | The x coordinate of the first point. |
| y1 | y₁ | The y coordinate of the first point. |
| z1 | z₁ | The z coordinate of the first point (3D only). |
| x2 | x₂ | The x coordinate of the second point. |
| y2 | y₂ | The y coordinate of the second point. |
| z2 | z₂ | The z coordinate of the second point (3D only). |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| distance | Distance d | The straight-line distance between the two points. |
| exact | Exact distance | The distance as a simplified square root, such as 3√5 or √2/2. |
| squared | Distance squared d² | The sum of the squared differences. |
| dx | Δx = x₂ − x₁ | The change in x from the first point to the second. |
| dy | Δy = y₂ − y₁ | The change in y from the first point to the second. |
| dz | Δz = z₂ − z₁ | The change in z (3D only). |
| steps | Working | The distance formula with the numbers put in, step by step. |

## Method

d = √((x₂ − x₁)² + (y₂ − y₁)²), with + (z₂ − z₁)² inside the root for points in 3D.

## Assumptions

- Coordinates are read exactly as typed (0.1 is 1/10), so d² is exact; the decimal distance is its square root rounded for display.
- The distance is in the same unit as the coordinates.
- The drawing shows the x and y coordinates only, also for points in 3D.

## Worked examples

1. dim = 2d, x1 = 1, y1 = 2, x2 = 4, y2 = 6 gives distance = 5, exact = 5, squared = 25, dx = 3, dy = 4, steps = d = √((4 − 1)² + (6 − 2)²); d = √(3² + 4²) = √(9 + 16) = √25; d = 5. Source: OpenStax, College Algebra 2e, §2.1, the distance formula (https://openstax.org/books/college-algebra-2e/pages/2-1-the-rectangular-coordinate-systems-and-graphs).
2. dim = 2d, x1 = -3, y1 = 5, x2 = 3, y2 = 2 gives distance = 6.708204, exact = 3√5, squared = 45, dx = 6, dy = -3.
3. dim = 3d, x1 = 1, y1 = 2, z1 = 3, x2 = 4, y2 = 6, z2 = 15 gives distance = 13, exact = 13, squared = 169, dz = 12.
4. dim = 2d, x1 = 0, y1 = 0, x2 = 0.5, y2 = 0.5 gives distance = 0.707107, exact = √2/2, squared = 0.5.
5. dim = 2d, x1 = 0.1, y1 = 0, x2 = 0.4, y2 = 0.4 gives distance = 0.5, exact = 1/2, squared = 0.25.

## FAQ

### What is the distance formula?

For points (x₁, y₁) and (x₂, y₂), d = √((x₂ − x₁)² + (y₂ − y₁)²). It is the Pythagorean theorem: the horizontal and vertical gaps are the legs of a right triangle, and the distance is its hypotenuse.

### How do I find the distance between two points step by step?

Subtract the x values and the y values, square both differences, add them, and take the square root. From (1, 2) to (4, 6): the differences are 3 and 4, the squares 9 and 16, the sum 25, and the distance √25 = 5.

### How do I simplify the square root in the answer?

Take out the largest square factor. √45 = √(9 × 5) = 3√5, and √(1/2) = √2/2. The calculator does this for you whenever the sum of squares is a fraction with a small enough top and bottom.

### 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. Δx and Δy do change sign.

### How do I find the distance between points in 3D?

Add the third difference inside the root: d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²). From (1, 2, 3) to (4, 6, 15) the differences are 3, 4, and 12, so d = √(9 + 16 + 144) = √169 = 13.

### Can the distance be negative?

No. It is a square root of a sum of squares, so it is 0 when the points are the same and positive otherwise.

### Can I use this for distances on a map?

Only on a flat grid, such as a floor plan or a map zoomed in on a small area. For places far apart on the Earth, use a great-circle distance, because the surface is curved.

## Sources

- OpenStax, College Algebra 2e, §2.1 The Rectangular Coordinate Systems and Graphs (the distance formula). https://openstax.org/books/college-algebra-2e/pages/2-1-the-rectangular-coordinate-systems-and-graphs
- OpenStax, Calculus Volume 3, §2.2 Vectors in Three Dimensions (the distance between two points in space). https://openstax.org/books/calculus-volume-3/pages/2-2-vectors-in-three-dimensions
