Distance Calculator
Last updated: November 4, 2026
Calculate the straight-line distance between two points in a flat Cartesian plane.
On this page
Quick summary: Calculate the straight-line distance between two points in a flat Cartesian plane.
Read the complete guide
Updated reference sections in this guide are in English.
Using this calculator
Enter two x/y coordinate pairs in a flat two-dimensional coordinate system. All coordinates must use one distance unit and compatible axis scales. The output is the direct segment length between the points, with the horizontal and vertical changes shown separately. Identical points are valid and have zero distance.
Calculation method
Distance = √(Δx² + Δy²)
This is the Pythagorean theorem applied to the horizontal and vertical legs of a right triangle. The implementation evaluates the length with Math.hypot, which avoids unnecessarily large or small intermediate squares. Signs determine direction in the component changes but not the nonnegative segment length.
Worked examples
A 3–4–5 segment
From (0, 0) to (3, 4), distance = √(9 + 16) = 5 units.
Crossing negative coordinates
From (−2, −1) to (1, 3), the changes are still 3 and 4, so the distance is again 5 units. Reversing the endpoints gives the same length.
Check this scenario in the calculator:
- First x coordinate
- 0
- First y coordinate
- 0
- Second x coordinate
- 3
- Second y coordinate
- 4
Understanding the result
If the coordinates are meters, the distance is meters. If they are pixels with equal horizontal and vertical scales, the answer is pixels. Do not append a squared-unit label: the square root converts squared component lengths back to a length.
Boundaries and assumptions
Coordinates are limited to ±10¹². This planar formula is not a route planner and does not account for obstacles or travel along roads. Latitude and longitude degrees are angles on a curved Earth, so entering them as x and y does not give a reliable geographic distance. Three-dimensional positions require another component.
Questions and reference
Can the answer be negative?
No. The changes in coordinates can be negative, but distance is nonnegative.
Can I use different units on the axes?
Convert them to a common length unit and scale before using this geometric formula.
Reference: OpenStax: rectangular coordinates and graphs.