Spreadsheet Practice

How to calculate the distance between two points in Excel

Formula (Excel and Google Sheets)

=SQRT((D2-B2)^2+(E2-C2)^2)

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

Result on the example
one result per row in F2, filled down to F6
Works in
Every current version
Google Sheets
Same formula

See it work

The formula is already in F2, filled down to F6. Change any input and the result updates, or edit the formula to experiment.

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.

=SQRT((D2-B2)^2+(E2-C2)^2)

Result5

  1. D23

    The value in D2.

  2. B20

    The value in B2.

  3. D2-B23

    The - operator subtracts.

  4. D2-B2)^29

    The ^ operator raises to a power.

  5. E24

    The value in E2.

  6. C20

    The value in C2.

  7. E2-C24

    The - operator subtracts.

  8. E2-C2)^216

    The ^ operator raises to a power.

  9. D2-B2)^2+(E2-C2)^225

    The + operator adds.

  10. SQRT((D2-B2)^2+(E2-C2)^2)5

    SQRT: Square root.

    • numberD2-B2)^2+(E2-C2)^225

In Google Sheets

The same formula works in Google Sheets: =SQRT((D2-B2)^2+(E2-C2)^2). We ran it in Google Sheets mode on the same data and it returns the same results.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=((D2-B2)^2+(E2-C2)^2)^0.55.00, 10.00, 10.00…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.

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Calculate the distance between two points

In F2, calculate the straight-line distance from (X1, Y1) to (X2, Y2), then fill down to F6.

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.

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.