# How to calculate the distance between two points in Excel

Use the Pythagorean formula: `=SQRT((D2-B2)^2+(E2-C2)^2)`.

**Excel:** `=SQRT((D2-B2)^2+(E2-C2)^2)` (Every current version)

**Google Sheets:** the same formula works.

## Example

Sample data (row 1 is the header):

| A | B | C | D | E | F |
| --- | --- | --- | --- | --- | --- |
| Segment | X1 | Y1 | X2 | Y2 | Distance |
| A | 0 | 0 | 3 | 4 |  |
| B | 1 | 2 | 7 | 10 |  |
| C | -2 | 5 | 4 | -3 |  |
| D | 2.5 | 1 | 7.5 | 13 |  |
| E | 10 | 10 | 12 | 7 |  |

Formula in F2, filled to F6: `=SQRT((D2-B2)^2+(E2-C2)^2)`

Result: 5.00; 10.00; 10.00; 13.00; 3.61

## How it works

The horizontal and vertical differences are the two short sides of a right triangle, and the distance is the long side: √(dx² + dy²). For segment A that is √(3² + 4²) = 5. Squaring makes the order of the points irrelevant, so negative differences are fine.

## Other ways

- `=((D2-B2)^2+(E2-C2)^2)^0.5`: Raising to the power 0.5 is the same as SQRT.

## Common mistakes

- Latitude and longitude are not flat X/Y coordinates. Over more than a few miles you need the haversine formula.
- Both coordinates must be in the same unit; mixing feet and meters gives a meaningless distance.

## Questions

**How do I calculate distance in 3D?**

Add the third difference: `=SQRT((D2-A2)^2+(E2-B2)^2+(F2-C2)^2)` with the coordinates laid out accordingly.

**How do I calculate distance between latitude and longitude?**

Use the haversine formula: `=6371*2*ASIN(SQRT(SIN(RADIANS(lat2-lat1)/2)^2+COS(RADIANS(lat1))*COS(RADIANS(lat2))*SIN(RADIANS(lon2-lon1)/2)^2))` gives kilometers.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/distance-between-two-points
