Distance Formula Calculator for 2D and 3D Points
Find the Euclidean straight-line distance between two points in a plane or in three-dimensional space. Review coordinate changes, the exact radical for supported integer inputs, the midpoint, a decimal answer and every formula step.
- 2D and 3D coordinates
- Stable large and tiny values
- Exact integer radicals
- Private browser calculation
Online Distance Between Two Points Calculator
Choose two or three dimensions, enter both points in one shared unit, and calculate the length of the direct line segment joining them.
From P = (-5, -3) to Q = (7, 2), the coordinate changes are 12 and 5.
Coordinate Contribution Breakdown
| Axis | Coordinate change | Squared term | Share of squared distance |
|---|---|---|---|
| x | 12 | 144 | 85.2071% |
| y | 5 | 25 | 14.7929% |
Calculation Steps
- Subtract coordinates: Δx = 7 - (-5) = 12 and Δy = 2 - (-3) = 5.
- Square the changes: 12^2 = 144 and 5^2 = 25.
- Add the squares: 144 + 25 = 169.
- Take the principal square root: distance = √169 = 13 coordinate units.
How to Use This Distance Formula Calculator
- Choose 2D or 3D. Use 2D for ordered pairs on an xy-plane. Use 3D for ordered triples in xyz-space.
- Select one shared unit. Choose coordinate units for abstract graph problems, or select a physical length unit when every axis uses that unit.
- Enter point P. Provide x1 and y1. In 3D mode, also provide z1.
- Enter point Q. Provide x2 and y2, plus z2 in 3D mode. Negative and decimal coordinates are valid.
- Choose display precision. This changes only the shown rounding. It does not change the stored coordinates or formula calculation.
- Calculate and review. Check the distance, exact supported radical, difference vector, midpoint, component table and substitution steps.
Read the point labels carefully before entering them. The first values belong to P and the second values belong to Q. Swapping the two complete points does not change distance, but mixing x- and y-coordinates creates a different segment.
What the Distance Formula Measures
The distance formula measures the length of the straight line segment between two Cartesian coordinate points. This is Euclidean distance. In a plane, the horizontal and vertical coordinate changes form the legs of a right triangle. The segment joining the points is its hypotenuse.
Distance is a scalar, so the result is never negative. The coordinate changes may be positive, negative or zero, but squaring removes their signs before they are added. This is why travelling from P to Q and from Q to P gives the same distance.
The formula describes a direct segment. It does not follow streets, curved paths, obstacles or the route an object travelled. It also does not treat latitude and longitude as flat x- and y-values. Geographic coordinates require an Earth model and a geodesic formula.
2D, 3D and Midpoint Formulas
Distance between two points in 2D
For P = (x1, y1) and Q = (x2, y2), first calculate Δx = x2 − x1 and Δy = y2 − y1. Then use:
Distance between two points in 3D
Three-dimensional space adds a perpendicular z-axis. For P = (x1, y1, z1) and Q = (x2, y2, z2), use:
The same pattern extends to more dimensions: subtract matching coordinates, square each change, add those squares, and take the nonnegative square root. This page focuses on 2D and 3D because they match common coordinate-geometry and spatial problems.
Midpoint of the segment
The midpoint is a separate result. It averages matching coordinates. In 2D, M = ((x1 + x2)/2, (y1 + y2)/2). In 3D, add (z1 + z2)/2. Midpoint locates the centre of the segment, while distance measures its length.
Worked Distance Formula Examples
Example 1: a 2D distance of 13
Let P = (−5, −3) and Q = (7, 2). The coordinate changes are Δx = 7 − (−5) = 12 and Δy = 2 − (−3) = 5.
The midpoint is ((−5 + 7)/2, (−3 + 2)/2) = (1, −0.5).
Example 2: an irrational 2D distance
For P = (10, −4) and Q = (−1, 5), Δx = −11 and Δy = 9. The squared changes total 121 + 81 = 202. Therefore d = √202, approximately 14.2126704 coordinate units. Rounding √202 to 14.21 is useful for display, but √202 preserves the exact value.
Example 3: distance in 3D space
For P = (3, −1, 5) and Q = (2, 1, −1), the difference vector is ⟨−1, 2, −6⟩. The distance is √(1 + 4 + 36) = √41, approximately 6.40312424 coordinate units. Its midpoint is (2.5, 0, 2).
Exact Radicals and Decimal Answers
An exact radical keeps the sum of squared changes under a square-root sign. If that integer is a perfect square, the radical becomes an integer. If it contains a square factor, the calculator simplifies the radical when the integer is within its practical simplification range. For example, √50 becomes 5√2.
The exact-radical label appears only when every entered coordinate is an exact integer and the resulting expression is short enough to display safely. The page does not call a radical based on rounded binary arithmetic exact. Decimal or scientific-notation inputs still receive a high-precision decimal distance and complete substitution steps.
Coordinate Units and Physical Length Units
Every coordinate in one calculation must use the same unit and scale. If x is in metres while y is in centimetres, convert one axis before entering the values. The squared terms use square units internally, but the final square root returns to the original linear unit.
| Input context | Select | Distance result |
|---|---|---|
| Abstract graph coordinates | Coordinate units | Coordinate units |
| Survey points measured in metres | Metres | m |
| Drawing dimensions in inches | Inches | in |
| Map grid positions in kilometres | Kilometres | km |
Selecting a physical unit changes the output labels only; it does not convert entered coordinates. Convert every axis to one shared unit before entering the points. The listed units follow exact defined relationships where applicable, including 1 inch = 0.0254 metre, 1 foot = 0.3048 metre, 1 yard = 0.9144 metre and 1 mile = 1609.344 metres.
Distance, Displacement, Slope and Midpoint
| Measure | What it describes | Sign or type |
|---|---|---|
| Straight-line distance | Length of the direct segment between two points | Nonnegative scalar |
| Difference vector | Coordinate change from P to Q | Directed components |
| Slope | Vertical change divided by horizontal change in 2D | Signed ratio or undefined |
| Midpoint | Point halfway along the segment | Ordered pair or triple |
| Path length | Length along the route actually followed | Nonnegative scalar |
Distance and slope use the same coordinate changes but answer different questions. A vertical segment has a valid distance but undefined slope because Δx = 0. Two journeys can share the same endpoints and straight-line distance while having different path lengths.
Accuracy, Large Coordinates and Calculator Limits
The engine uses a scaled hypotenuse calculation rather than directly evaluating Δx2 + Δy2 with ordinary floating-point multiplication. This protects many legitimate large and microscopic component values from premature overflow or underflow.
Coordinate subtraction needs separate care. Decimal strings are compared and subtracted with integer-coefficient arithmetic before the difference is converted for the hypotenuse step. This prevents a false zero in examples such as 10000000000000000 and 10000000000000001, which ordinary browser numbers may otherwise store as the same value.
The calculator stops with a clear message when an entered coordinate, exact difference, midpoint or final distance is outside the supported browser number range. It also keeps a genuine tiny nonzero result in scientific notation rather than rounding it to zero. For measured data, the displayed digits do not create extra measurement accuracy. Match your final rounding to the precision and uncertainty of the original coordinates.
Common Distance Formula Mistakes
- Subtracting x from y. Always pair x2 with x1, y2 with y1, and z2 with z1.
- Forgetting parentheses around a negative coordinate. For example, 7 − (−5) equals 12, not 2.
- Adding raw changes before squaring. Square each component separately, then add the squared terms.
- Leaving out the square root. The sum of squares is the squared distance, not the final distance.
- Using different axis scales or units. Convert all coordinates to one consistent scale first.
- Expecting route or geographic distance. Cartesian Euclidean distance is a direct flat-space segment.
- Rounding intermediate changes. Keep full coordinate precision and round only the final displayed answer.
Related Calculators
Continue with the Science & Engineering Calculators directory, or open a related coordinate and geometry tool.
Distance Formula Calculator FAQs
What is the distance formula between two points?
For 2D points, use d = square root of [(x2 - x1)^2 + (y2 - y1)^2]. It is the Pythagorean theorem applied to the horizontal and vertical coordinate changes.
How do I calculate distance in 3D?
Add the squared z-coordinate change: d = square root of [(x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2]. All three axes must use the same scale and unit.
Can the distance between two points be negative?
No. Coordinate changes can be negative, but their squares are nonnegative. The principal square root therefore returns a distance greater than or equal to zero.
What is the distance between identical points?
It is zero. Every matching-coordinate difference equals zero, so the square root of the sum of squared changes is also zero.
Does reversing the two points change the distance?
No. Reversing the points changes the sign of every difference, but squaring those differences gives the same sum and the same distance.
Why is the distance formula based on the Pythagorean theorem?
In 2D, the horizontal and vertical changes are perpendicular legs of a right triangle. The segment between the points is its hypotenuse, so its squared length equals the sum of the squared leg lengths.
What is the difference between distance and midpoint?
Distance is the nonnegative length of the segment. Midpoint is the coordinate point halfway along it, found by averaging the matching endpoint coordinates.
Can I enter negative or decimal coordinates?
Yes. The calculator accepts negative values, zero, decimals and scientific notation. Enter complete numbers without commas, unit text or arithmetic expressions.
Does this calculate road or geographic distance?
No. It calculates a straight Euclidean segment in a Cartesian coordinate system. Routes, obstacles and latitude-longitude coordinates require different data and formulas.
When does the calculator show an exact radical?
It shows an exact or simplified radical when all entered coordinates are exact integers and the expression is short enough to display safely. Other valid inputs receive a decimal result and formula steps.
Method References
The 2D formula and its Pythagorean derivation were checked against OpenStax College Algebra. The 3D extension was checked against OpenStax Calculus Volume 3. Physical unit labels and relationships were reviewed against NIST length guidance.
Educational note: This calculator assumes a Cartesian coordinate system with perpendicular axes using one consistent scale. Verify the coordinate system, units and required rounding before using the result in graded, engineering, surveying or safety-critical work.