Distance - 2D and 3D Euclidean Formula
Use this distance calculator to find the Euclidean distance between two points in 2D or 3D, with the formula, per-axis differences, and midpoint.
Distance
Results
What Is a Distance Calculator?
A distance calculator finds the straight-line distance between two points using the Euclidean distance formula. It works for both 2D points (x, y) and 3D points (x, y, z) through a single mode toggle, and shows the result, the per-axis differences, the squared distance, and the midpoint in one pass. That makes it the everyday analytic-geometry tool for the question, 'how far apart are these two points?'
- • Math homework and analytic geometry: Confirm a problem that asks for the distance between two points, the midpoint, or the length of a segment, including cases that come out to neat Pythagorean triples.
- • Coordinate geometry and graphing: Plot two points on a coordinate plane or in 3D, then read the distance and the midpoint without re-entering numbers into a separate tool.
- • Mapping and screen coordinates: Measure the pixel or grid distance between two on-screen locations when you are working out positions for a layout, sprite, or design grid.
- • Physics and engineering preliminaries: Compute the magnitude of a 2D or 3D displacement vector, which is just the Euclidean distance from the start point to the end point.
The distance calculator is intentionally general: it answers the Euclidean distance question for both the planar case (two coordinates per point) and the spatial case (three coordinates per point). The mode toggle is the only thing that changes; the math is the same idea, with one extra squared term in 3D.
The per-axis differences, the squared distance, and the midpoint all show alongside the final answer, so you can see which arithmetic produced the result. That makes it useful as a teaching aid, not just a black-box answer machine.
If the answer is in generic "units" and you only need the planar case without the mode toggle, the 2D Distance Calculator page is the dedicated 2D version with the same formula and an extra slope output.
How the Distance Calculator Works
The page implements the standard Euclidean distance formula in 2D and 3D. It takes the two coordinate inputs, builds the per-axis differences, squares and sums them, and takes the square root.
- x1, y1, z1: Coordinates of the first point. In 2D mode, z1 is treated as 0.
- x2, y2, z2: Coordinates of the second point. In 2D mode, z2 is treated as 0.
- Δx, Δy, Δz: Per-axis differences between the two points, signed.
- d = sqrt(Δx² + Δy² + Δz²): The Euclidean distance, always non-negative.
The same formula works for negative coordinates and decimal coordinates. Squaring removes the sign of each per-axis difference, so the distance is always non-negative no matter which point you call first.
Switching the mode toggle from 2D to 3D does not change the x and y math; it only adds the z term.
Worked example: the 3-4-5 right triangle in 2D
Point 1: (0, 0). Point 2: (3, 4). Mode: 2D.
Δx = 3. Δy = 4. Δz = 0. d = sqrt(3² + 4² + 0²) = sqrt(9 + 16) = sqrt(25).
d = 5 units.
The two points form a 3-4-5 right triangle with the axes, and the distance comes out to a clean integer. The same shape is also a Pythagorean triple, which is why this example is a favorite in textbooks.
Worked example: 3-4-12 rectangular box in 3D
Point 1: (0, 0, 0). Point 2: (3, 4, 12). Mode: 3D.
Δx = 3. Δy = 4. Δz = 12. d = sqrt(3² + 4² + 12²) = sqrt(9 + 16 + 144) = sqrt(169).
d = 13 units.
The two points sit on opposite corners of a 3-4-12 rectangular box, and the space diagonal across that box is exactly 13 units. The 3-4-5-12-13 chain is the same Pythagorean-triple idea extended to a third axis.
According to Khan Academy, the distance between two points (x1, y1) and (x2, y2) on a coordinate plane is computed as the square root of (x2 - x1)^2 + (y2 - y1)^2, which is the Pythagorean theorem applied to the right triangle formed by the two points.
If you work in 3D most of the time and want a page that always shows the z inputs, the 3D Distance Calculator page skips the mode toggle and applies the full 3D formula directly.
Key Concepts Behind the Distance Formula
Four ideas explain why the formula is what it is and what the result really means in 2D and 3D.
Pythagorean theorem
Drop perpendiculars from the two points to form a right triangle. The two legs are Δx and Δy, and the hypotenuse is the distance d. In 3D, the same idea extends to a rectangular box with Δz as the third leg and d as the space diagonal.
Euclidean distance
It is the length of the shortest possible path between the two points: a straight line. Squared differences are added before the square root, which means the distance is non-negative and follows the triangle inequality.
Squared distance
The value under the square root, Δx² + Δy² + Δz², is the squared distance. Many machine-learning and clustering tools work with the squared distance instead of d to avoid an unnecessary square root.
Midpoint
The midpoint of the segment between the two points is ((x1 + x2) / 2, (y1 + y2) / 2, (z1 + z2) / 2). It is the average of the two coordinates in each direction and lies exactly halfway along the line.
The 3-4-5 and 3-4-12-13 examples are special cases of Pythagorean triples, and if you generate many pairs of points and want a quick way to spot the ones that come out to integers, the Pythagorean Triples Calculator page does that directly.
How to Use This Distance Calculator
Five short steps cover every common case, from a clean 2D textbook example to a 3D space diagonal.
- 1 Pick the mode: Choose 2D to use x and y only, or 3D to also use z. The page keeps the existing x and y values when you switch modes.
- 2 Enter point 1: Type x₁, y₁, and (in 3D mode) z₁. The default is (0, 0, 0); change all three values if your point is somewhere else.
- 3 Enter point 2: Type x₂, y₂, and (in 3D mode) z₂. The default is (3, 4, 12) so the example starts as the classic 3-4-12-13 space diagonal.
- 4 Read the distance and supporting values: The primary output is the Euclidean distance d, updated as you type. The supporting values show Δx, Δy, Δz, the squared distance, and the midpoint in one pass.
- 5 Reset or change units if needed: Click Reset to return to the example. If the answer is in generic units and you want meters, feet, or pixels, open the Distance Converter in a new tab.
Try the points (−1, 2, −3) and (4, −1, 2) in 3D mode. The calculator gives Δx = 5, Δy = −3, Δz = 5, d = sqrt(59) ≈ 7.6811, and midpoint (1.5, 0.5, −0.5).
Once you have the distance in generic units and want meters, feet, miles, or pixels instead, the Distance Converter page changes the unit of the result without redoing the arithmetic.
Benefits of Using This Distance Calculator
These benefits matter most when you are working a problem by hand and need a quick, trustworthy check across both 2D and 3D.
- • One tool for 2D and 3D: A single mode toggle swaps between the 2D and 3D formulas, so you do not have to pick a different page based on the dimension of your problem.
- • Skip the arithmetic mistakes: Manual distance problems are easy to get wrong on the squaring step. The calculator handles the squaring and square root so you can focus on setting up the problem.
- • See the full step-by-step math: The page shows Δx, Δy, Δz, the squared distance, and the final d, which makes it a good way to check your own work, not just a way to get a number.
- • Get the midpoint for free: You often need the midpoint of a segment at the same time as the distance. The calculator returns both from the same six inputs.
- • Handle any sign or scale of coordinate: Negative coordinates, decimal coordinates, and points far from the origin all use the same formula.
Use the page to confirm a homework answer, sanity-check a graphics calculation, or pre-validate a coordinate pair.
If you would rather see the magnitude of a single 2D or 3D vector that starts at the origin, the Vector Magnitude Calculator page runs the same arithmetic on one vector instead of two points.
Factors That Affect the Distance Result
The formula is the same in every case, but a few factors change how the result should be read.
Order of the two points
Swapping point 1 and point 2 flips the sign of every per-axis difference, which leaves the squared values, the distance, and the midpoint unchanged. The order of the inputs does not change the length of the segment.
Coordinate scale and unit
The result is in the same unit as the coordinates. If x, y, and z are in centimeters, d is in centimeters. If you need meters, feet, or pixels, use the Distance Converter on the result.
Mode toggle (2D vs 3D)
Switching modes does not change x and y, but it adds or removes the z term. In 3D with z1 = z2 = 0 the result matches the 2D result for the same x and y.
Sign of the coordinates
Negative coordinates work the same as positive coordinates because the formula squares each per-axis difference before adding. The result is always non-negative.
- • This page assumes a flat Euclidean plane (2D) or flat Euclidean space (3D). It does not account for distance on the surface of a sphere (great-circle), along a road network (Manhattan), or along a curve (arc length).
- • The result is the straight-line distance, not the path length. If the points lie on a curve, the straight-line distance is a lower bound on the path length, not the path length itself.
- • In 2D mode the z values are treated as 0, so a 3D problem with nonzero z must use 3D mode. The dz value in the result is a quick way to confirm that the mode you picked matches the problem.
These caveats are not flaws of the formula; they are the boundary between straight-line Euclidean distance and the other distance concepts that show up in geography, routing, and calculus.
According to Wolfram MathWorld, the Euclidean distance between two points in three-dimensional space is given by d = sqrt((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2), which generalizes the Pythagorean theorem to a third axis.
When the two points sit on a known curve and the path length between them matters more than the straight-line distance, the Arc Length Calculator page integrates the distance along that curve.
Frequently Asked Questions
Q: What is the formula for the distance between two points?
A: In 3D, the formula is d = sqrt((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2). In 2D the z term drops out and the formula becomes d = sqrt((x2 - x1)^2 + (y2 - y1)^2). Subtract the coordinates, square each difference, add the squares, and take the square root.
Q: How do I calculate the distance between two points in 2D and 3D?
A: Pick the mode (2D or 3D), then enter the coordinates of the first point as x1 and y1 (plus z1 in 3D) and the coordinates of the second point as x2 and y2 (plus z2 in 3D). The calculator returns the Euclidean distance, the per-axis differences, the squared distance, and the midpoint in one pass.
Q: What is the difference between the 2D and 3D distance formulas?
A: The 2D formula is d = sqrt((x2 - x1)^2 + (y2 - y1)^2). The 3D formula adds a third squared term for the z difference, giving d = sqrt((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2). On a flat surface, the 3D formula with z1 = z2 = 0 reduces to the 2D formula.
Q: Can the distance between two points ever be negative?
A: No. The distance is a length, so it is always non-negative. Squaring the per-axis differences makes the under-the-root value non-negative, and the principal square root is non-negative too.
Q: What happens if both points are the same in the distance calculator?
A: If every coordinate of point 1 matches the corresponding coordinate of point 2, all per-axis differences are zero, the squared distance is zero, and the distance is exactly 0. The midpoint equals the original point.
Q: How accurate is the distance calculator?
A: The result is exact up to the displayed four-decimal precision. Because the underlying formula is a direct application of the Pythagorean theorem (with one extra squared term in 3D), there is no approximation in the math itself; any small difference comes from rounding the final number for display.