Back to home

Distance Calculator

Calculate the distance between two points in 2D or 3D space.

Point Coordinates
Enter coordinates for both points

Point 1

Point 2

About Distance Calculation

The distance formula is a direct application of the Pythagorean theorem. In 2D, the horizontal and vertical separations between two points form the legs of a right triangle, and the distance is the hypotenuse: d = √((x₂−x₁)² + (y₂−y₁)²). The 3D version extends naturally by adding the z-component: d = √((x₂−x₁)² + (y₂−y₁)² + (z₂−z₁)²).

The midpoint formula finds the center point between two points. In 2D it is ((x₁+x₂)/2, (y₁+y₂)/2), and in 3D it adds ((z₁+z₂)/2). The slope of a line through two points, m = (y₂−y₁)/(x₂−x₁), describes how steep the line is. A slope of 0 means horizontal; undefined slope (division by zero) means vertical.

Distance calculations are fundamental in coordinate geometry, physics (displacement), GPS systems, computer graphics (rendering and collision detection), and data science (nearest-neighbor algorithms like k-NN). The Euclidean distance formula used here is the most common metric, though other distance metrics like Manhattan distance are used in specialized contexts.

Calculate straight-line Euclidean distance between two points in 2D or 3D Cartesian coordinates. This tool is for coordinate geometry, not map routes, latitude/longitude or GPS distances.

How it works

Subtract matching coordinates. In 2D, distance = √[(x₂−x₁)²+(y₂−y₁)²]; in 3D add (z₂−z₁)² inside the square root. The implementation uses a scaled hypotenuse calculation to avoid unnecessary overflow from squaring large values. Midpoints average matching coordinates; the 2D slope is Δy/Δx when defined.

Worked examples

From (0,0) to (3,4), differences are 3 and 4. Distance=√(9+16)=5. The midpoint is (1.5,2), and slope=4/3≈1.333333.

From (−1,2,0) to (2,6,12), differences are 3,4,12. Distance=√(9+16+144)=√169=13. Negative coordinates do not make a distance negative.

Why the formulas contain squares

In a plane, the horizontal and vertical displacements form perpendicular sides of a right triangle. If those sides are Δx and Δy, the Pythagorean theorem gives d² = Δx² + Δy². Taking the nonnegative square root gives the length of the segment joining the points. A displacement may be negative, but squaring removes its direction.

For three dimensions, first find the horizontal-plane length h = √(Δx² + Δy²). This length and the vertical displacement Δz form another right triangle. Therefore d² = h² + Δz² = Δx² + Δy² + Δz². This derivation requires perpendicular axes measured on the same scale, not arbitrary columns with incompatible units.

Straight-line distance versus a permitted route

Between (0,0) and (3,4), Euclidean distance is 5 units. Manhattan distance is |3| + |4| = 7 units: it measures a route restricted to horizontal and vertical movement. In three dimensions the analogous sum is |Δx| + |Δy| + |Δz|. This calculator reports Euclidean distance, not that sum.

Neither quantity automatically describes travel on a real road network. Obstacles, one-way streets and bridges may force longer routes. Latitude and longitude are angles on a curved Earth, so entering them here does not produce a reliable kilometer or mile distance. Geographic calculations require great-circle formulas for a spherical model or an appropriate ellipsoidal geodesic method; driving distance additionally requires route data.

Decimal coordinates work the same way as integers. From (0.5,0.5) to (2,2.5), the differences are 1.5 and 2, giving √(2.25 + 4) = 2.5 units. Keep the original coordinate precision when comparing measurements: rounding both points before subtraction can noticeably change a short separation.

How to read your result

Use the same coordinate unit and scale on every axis. The output has that length unit, while slope is a ratio. Values are finite floating-point numbers and displayed to six decimal places with unnecessary trailing zeros removed; sufficiently small distances can display as zero. Identical points have distance zero and undefined slope; a vertical line also has undefined slope. Unrepresentable differences or results receive a validation error rather than Infinity.

For related calculations, try pythagorean theorem calculator, slope calculator, right triangle calculator.

Frequently asked questions

Can I use latitude and longitude?

No. Geographic coordinates lie on a curved Earth and angular units do not have a constant Cartesian distance scale. Use an appropriate geographic distance method instead.

Do negative coordinates work?

Yes. Coordinate differences are squared in the Euclidean formula, so the resulting distance is nonnegative.

What if the two points are identical?

The distance is zero and the midpoint is the same point. A unique line and slope cannot be determined from two identical points.

Does the 3D formula include height?

Yes, if height is represented by the z coordinate in the same linear units as x and y. The squared z difference is added to the squared x and y differences.

Can I enter very large coordinates?

Finite values are accepted when their differences and resulting distance remain representable. A scaled hypotenuse calculation handles many large values that naive squaring would overflow, but it cannot exceed floating-point range.

How is Manhattan distance different?

Manhattan distance adds absolute coordinate differences, while Euclidean distance takes the square root of their squared sum. From (0,0) to (3,4), these are 7 and 5 units respectively.

Sources: Pythagorean theorem and standard Cartesian Euclidean-distance and midpoint definitions.

Last reviewed: November 3, 2026

Take this calculation further

Browse the math calculators collection for more tools in this subject.

For a related calculation, use Slope Calculator to calculate slope, y-intercept, line equation, and angle of inclination from two points. Alternatively, use Triangle Calculator to solve any triangle from SSS, SAS, ASA, AAS, or SSA inputs using the Law of Sines and Law of Cosines.

For the underlying method, read How to Solve Any Triangle: Law of Sines vs. Law of Cosines.