Distance Calculator

Enter two points on a flat plane or in 3D space and get the straight-line distance instantly, with the midpoint, the component steps, the slope and the line equation, and a drawing that shows the right triangle hiding inside the formula.

What you get
  • 2D and 3D in one toolFlip to space coordinates and the third axis joins in.
  • Every related figureMidpoint, slope, line equation and component steps.
  • Drawing to scaleThe segment, its legs and the midpoint, plotted on a grid.

Your two points

Results update as you type

Two points on a flat coordinate plane. Negative coordinates and decimals are fine.

First point

Second point

Runs entirely in your browser. Nothing you type is sent or saved

Distance guide

What the distance formula measures

Give any two points and the distance formula returns the length of the straight segment joining them, the shortest possible path between the two positions. On a coordinate plane the points are pairs like (0, 0) and (3, 4); in space they are triples like (1, 2, 3) and (4, 6, 3). The formula needs nothing but the coordinates, which is why it sits at the heart of game engines, GPS software, collision detection and every map that ever measured "how far" with a tap of two fingers.

This page works through the pair (0, 0) and (3, 4) as its running example, so every number below can be checked against the calculator above. Their distance is exactly 5.

The 2D and 3D distance formulas

On a flat plane, subtract the coordinates, square the differences, add the squares, and take the square root:

d = √(x2 - x1)2 + (y2 - y1)2

(x1, y1) first point · (x2, y2) second point

For the example points: the x difference is 3 - 0 = 3, the y difference is 4 - 0 = 4, so d = √(3² + 4²) = √(9 + 16) = √25 = 5. In three dimensions one more squared difference joins the sum:

d = √(x2 - x1)2 + (y2 - y1)2 + (z2 - z1)2

Take the points (1, 2, 3) and (4, 6, 3): the differences are 3, 4 and 0, so d = √(9 + 16 + 0) = 5 again. The two points share a z coordinate, which means they both sit in the same horizontal slice of space and the third axis contributes nothing. The classic 3D example is the space diagonal of a unit cube, from corner (0, 0, 0) to the opposite corner (1, 1, 1): d = √(1 + 1 + 1) = √3 = 1.732051, a number carpenters meet whenever they measure across a box instead of along its edges.

Pythagoras hiding underneath

The distance formula is not a new theorem; it is the Pythagorean theorem wearing coordinates. Between the points (0, 0) and (3, 4) you can walk a horizontal leg of 3 and then a vertical leg of 4, tracing a right triangle whose hypotenuse is the straight segment. The legs are exactly the coordinate differences, so "the square of the hypotenuse equals the sum of the squares of the legs" becomes "the distance squared equals dx squared plus dy squared".

The drawing above your results makes this visible: it plots both points, the segment between them, and the dashed right-triangle legs labeled dx and dy, with the right-angle corner marked. In 3D the same idea holds with three mutually perpendicular legs, which is why the formula simply gains a third squared term.

Two side results come free with this picture. The slope of the segment is the rise over the run, dy ÷ dx, which for the example is 4 ÷ 3 = 1.3333. And the line equation through the two points follows from the slope and any one point: here y = 1.3333x + 0, which the calculator reports whenever the two points share neither x coordinate.

The midpoint: the average of two positions

The point exactly halfway along the segment is found by averaging the coordinates: midpoint = ((x1 + x2) ÷ 2, (y1 + y2) ÷ 2). For (0, 0) and (3, 4) that is (1.5, 2), and for the 3D pair (1, 2, 3) and (4, 6, 3) it is (2.5, 4, 3). The same averaging extends to any dimension, one division by 2 per axis.

The midpoint is more useful than it looks. It is the natural center for anything defined by two extremes: the midpoint of a commute sets a fair meeting spot, the midpoint of two prices anchors a negotiation, and in graphics the midpoint of a segment seeds recursive subdivision. Because averaging ignores the distance entirely, the midpoint between (0, 0) and (1,000,000, 0) is still just (500,000, 0).

Distance vs displacement

Physics separates two ideas that everyday language merges. Distance is the length of the actual path traveled; displacement is the straight segment from start to end, regardless of the path. This calculator computes the displacement: the shortest possible separation between the two points.

Walk one full lap of a 400 meter track and your distance traveled is 400 meters, but your displacement is 0, because you finished where you started. Drive 3 blocks east and 4 blocks north and the odometer reads 7 blocks, while your displacement is the √(3² + 4²) = 5 block diagonal a bird would fly. Whenever a question says "how far apart", "as the crow flies" or "straight-line", it wants the quantity on this page; whenever it says "how long is the route", it wants path length, which needs the shape of the path and is a different calculation.

Using the calculator well

  • Keep coordinate order consistent: subtract first from first and second from second. The formula is symmetric, so swapping which point is "first" changes nothing, but pairing x2 with y1 silently produces a meaningless number. The labeled fields protect you from the common version of this slip.
  • Units flow through: enter coordinates in meters and the distance comes back in meters, with the midpoint in meters too. The formula never mixes or converts units.
  • Latitude and longitude are not flat coordinates: treating degrees of latitude and longitude as x and y gives badly wrong answers for real places, because degrees of longitude shrink toward the poles and the Earth's surface is curved. For geographic questions, convert to a projected grid first or use a great-circle (haversine) tool.
  • Negatives are welcome: the differences get squared, so points on opposite sides of an axis work exactly like any others. The pair (-2, -1) to (4, 3) is an ordinary √(36 + 16) = 7.2111 away.
  • Same coordinates give zero: enter two identical points and the distance is 0, which is the correct answer, not an error.
  • Check plausibility: a rough mental estimate from the legs (here, a bit more than 4) catches transposed digits instantly. The squared-components table in the results shows every intermediate value for exactly this purpose.

A short history of measuring with coordinates

The distance formula became possible only after points learned to carry numbers. René Descartes, in his 1637 appendix La Géométrie, fused algebra with geometry by describing every point in the plane with a pair of measurements from fixed axes, the coordinate idea now bearing his name. Pierre de Fermat developed the same machinery independently around the same time. Once points were numbers, questions like "how far apart?" turned into calculations, and the Pythagorean theorem, known for two thousand years, automatically became the distance formula.

The three-dimensional extension is a direct generalization that matured with analytic geometry in the 1700s, through the work of Euler and others who moved geometry into space with triples of coordinates. Today the same formula, unchanged, runs inside every video game frame, every robot arm controller and every ride-sharing ETA: each of those systems is, at bottom, squaring coordinate differences and taking a square root, millions of times per second.

Common questions

No. Because the coordinate differences are squared, their signs vanish, so (3, 4) to (0, 0) is the same distance as (0, 0) to (3, 4). The one requirement is consistency: pair each x with the other x and each y with the other y. Swapping which point is first is safe; mixing the coordinates of the two points is not.

That coordinate simply contributes zero. Two points with the same y lie on a horizontal line, so the distance is just the absolute difference in x; same x gives a vertical segment, and in 3D a shared z means both points sit in one horizontal plane. The vertical pair (2, 1) to (2, 7), for example, is exactly 6 apart, and its slope is undefined because the run is zero.

Not directly. Degrees of longitude represent shorter real distances as you approach the poles, and the Earth's surface is curved, so flat Pythagoras on raw degrees can be off by tens of percent. For genuine geographic distances, project the coordinates onto a local flat grid for small areas, or use a great-circle formula such as haversine for long routes. This page is for coordinate planes, which is what maps, games and CAD systems actually use internally.

Because it is the square root of a sum of squares: every squared difference is zero or positive, so the total is zero or positive and the root inherits that. A negative distance has no geometric meaning, which is why any chain of algebra that produces one signals an error upstream, usually an unsquared difference.

Distance is the length of the path actually taken; displacement is the straight segment from start to finish. Walking 3 blocks east then 4 north covers a distance of 7 blocks while producing a displacement of 5. This calculator always returns the straight-line value, the answer to "how far apart", not "how long was the route".

It is the same Pythagorean build with one more leg. In 3D you can first collapse the x and y differences into a flat distance with the 2D formula, then treat that result as one leg of a vertical right triangle whose other leg is the z difference. Applying Pythagoras once more produces exactly the three-term square root, which is why no new mathematics is needed to leave the plane.

That is a different quantity: the shortest segment must meet the line at a right angle, and the standard formula for a line ax + by + c = 0 and point (x0, y0) is |ax0 + by0 + c| ÷ √(a² + b²). This page measures point to point. For point to line, pick two points on the line for context and compute the perpendicular distance separately, or use a tool dedicated to that formula.

No. Every calculation runs in your browser. Nothing is stored or transmitted.

Two points in. One honest number out.

Browse all math calculators