Skip to content
Other

Distance Between Two Points Calculator

Calculate the straight-line distance between any two coordinate points in 2D or 3D space. Get the exact distance, the midpoint of the segment, the slope of the line (2D), and a simplified radical expression, all with a full step-by-step breakdown.

Your details

Switch between flat-plane (2D) and three-dimensional (3D) distance.
Distance
5

Euclidean straight-line distance between the two points.

Exact (radical form)5
Horizontal (Δx)3
Vertical (Δy)4
Midpoint x1.5
Midpoint y2
Slope (m)1.333333
Δx (horizontal)3
Δy (vertical)4
Δz (depth)-

The straight-line distance is 5.0000.

  • This is the Euclidean (as-the-crow-flies) distance in the coordinate plane, the hypotenuse of the right triangle formed by the horizontal and vertical separations.
  • The midpoint of the segment is (1.5000, 2.0000).
  • The slope of the line through these two points is 1.3333 (rise over run).
  • Swapping which point is labeled first and which is second leaves the distance unchanged.

Next stepTo find the equation of the line through these points, use the slope and one point in y - y1 = m(x - x1).

Formula

d=(x2x1)2+(y2y1)2(2D),d=(x2x1)2+(y2y1)2+(z2z1)2(3D)d = \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}\quad\text{(2D)},\quad d = \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2 + (z_2-z_1)^2}\quad\text{(3D)}

Worked example

From (0, 0) to (3, 4): d = sqrt(3^2 + 4^2) = sqrt(9 + 16) = sqrt(25) = 5. Midpoint = (1.5, 2). Slope = (4-0)/(3-0) = 4/3.

How the distance formula works

The distance formula is a direct application of the Pythagorean theorem. Draw a right triangle whose hypotenuse connects your two points: the horizontal leg has length |x2 - x1| and the vertical leg has length |y2 - y1|. The theorem says hypotenuse^2 = leg1^2 + leg2^2, so distance = sqrt((x2 - x1)^2 + (y2 - y1)^2). In 3D you simply add a third squared term for the z-axis, which is why the two formulas look identical apart from that extra component. The result is always non-negative, and swapping which point is called "1" and which is called "2" leaves the answer unchanged because the differences are squared.

Exact radical form vs. decimal approximation

When the squared sum is an integer, the distance can often be expressed as a simplified surd. For example, sqrt(50) simplifies to 5*sqrt(2) because 50 = 25 * 2 and sqrt(25) = 5. The radical form is the exact answer: it has no rounding error at all. The decimal approximation is useful for engineering and science, where you typically need a specific number of significant figures. This calculator gives you both. The simplification algorithm factors perfect squares out of the number under the radical sign, the same method you would use by hand.

Midpoint and slope from the same two points

The midpoint of a segment is simply the average of the x-coordinates and the average of the y-coordinates: M = ((x1 + x2) / 2, (y1 + y2) / 2). In 3D the same logic extends to z. The slope of the line through two points in 2D is the rise divided by the run: m = (y2 - y1) / (x2 - x1). If the two x-coordinates are equal the line is vertical and the slope is undefined (division by zero). Slope is not defined in 3D because infinitely many planes and directions pass through two 3D points; you would use a direction vector instead.

2D vs 3D and when to use each

Choose 2D when your points live on a flat coordinate plane: graph paper problems, pixel positions on a screen, or any scenario with only horizontal and vertical components. Choose 3D when you have a height or depth dimension as well, for example the positions of atoms in a molecule, vertices of a 3D model, or the corners of a room. For distances between real-world geographic locations (cities, GPS coordinates) neither formula applies directly because the Earth is curved; you need a haversine or Lambert formula that accounts for spherical or ellipsoidal geometry.

Applications across science and everyday life

The Euclidean distance formula appears in more places than you might expect. In data science and machine learning, the k-nearest-neighbors algorithm classifies new data points by measuring Euclidean distance to all training examples, and k-means clustering assigns points to the nearest centroid. In robotics and game development, pathfinding algorithms use the distance formula as a heuristic. In physics, the distance between two charged particles or masses determines the force between them via the inverse-square law. Even GPS receivers use a generalized 3D version to triangulate position from satellite signals.

Distance formula by dimension

SpaceFormulaNotes
1D (number line)d = |x2 - x1|Absolute value of the difference
2D planed = sqrt((x2-x1)^2 + (y2-y1)^2)This calculator's default mode
3D spaced = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)Switch to 3D above
n-D (general)d = sqrt(sum of (ai - bi)^2)Used in machine learning and data science
Earth surfaceHaversine / Lambert formulaNeeded for geographic lat/lon distances

All versions use the same Pythagorean idea: sum the squares of the coordinate differences, then take the square root.

Frequently asked questions

Is Euclidean distance the same as straight-line distance?

Yes. Euclidean distance is the formal name for the straight-line, or as-the-crow-flies, distance between two points. It is the length of the shortest possible path connecting them in a flat plane, with no detours around obstacles. The term "Euclidean" comes from Euclid of Alexandria, whose axioms define the geometry of flat space.

Can this calculator handle negative coordinates?

Fully. The formula squares both differences before adding them, so negative x or y values produce the same result as their positive counterparts at the same distance from the origin. Coordinates like (-3, -7) are treated exactly like any other real-number inputs. The sign cancels out in the squaring step.

What is the exact (radical) form of the distance?

When the sum of the squared differences is an integer, the square root can often be simplified. For example, sqrt(72) = sqrt(36 * 2) = 6*sqrt(2). This exact form has no rounding error, unlike the decimal approximation. It is particularly useful in geometry proofs and algebra problems where you need to keep the answer exact before substituting into a larger expression.

How does the 3D distance formula differ from the 2D one?

The 3D formula adds one more squared term for the z-axis: d = sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2). The reasoning is the same as in 2D: apply the Pythagorean theorem twice, first to find the diagonal across the base of the box formed by the two points, then to find the space diagonal using that base diagonal and the vertical difference. The result is the length of the longest diagonal of a rectangular box whose opposite corners are your two points.

How is the midpoint calculated?

The midpoint M of a segment from (x1, y1) to (x2, y2) is ((x1 + x2) / 2, (y1 + y2) / 2). You simply average the corresponding coordinates. In 3D add a third component: ((z1 + z2) / 2). The midpoint is equidistant from both endpoints, so the distance from either endpoint to M is exactly half the total segment length.

When is the slope undefined, and why?

The slope is undefined when the two points have the same x-coordinate, making the denominator x2 - x1 equal to zero. A vertical line rises or falls infinitely steeply, and no finite ratio can describe that steepness. This is distinct from a slope of zero, which describes a perfectly horizontal line. The calculator shows "undefined" in this case rather than returning an error or a very large number.

Why should I use a haversine formula instead of this one for map distances?

The Euclidean formula assumes a flat plane. The Earth is roughly spherical (more precisely an oblate spheroid), so coordinates given as latitude and longitude represent points on a curved surface. Two cities 1,000 km apart are not connected by a straight line passing through the Earth but by an arc along the surface. The haversine formula accounts for this curvature and gives the correct great-circle (shortest-surface-path) distance. For small distances of a few kilometers the flat-plane approximation is close enough, but for anything intercity or international you need the spherical formula.

Sources

Written by Dr. Elena Vasquez, PhD Mathematician · Lisbon, Portugal

Translating rigorous geometric theory into accurate, reliable calculation tools trusted by engineers, students, and researchers worldwide.

Search 3,500+ calculators

Loading search…