๐Ÿ‡บ๐Ÿ‡ธ USC
Math & Conversion
๐Ÿ“

Distance Calculator

Distance between two points in 2D or 3D, plus the midpoint

๐Ÿ“ Two points

Point A (xโ‚, yโ‚)
Point B (xโ‚‚, yโ‚‚)

๐Ÿ“ Distance

5
units between A and B
Exact value
โˆš25
Midpoint
(2.5, 4)

๐Ÿงฎ Step by step

  1. 1. Find the differences.
    ฮ”x = 4 โˆ’ 1 = 3
    ฮ”y = 6 โˆ’ 2 = 4
  2. 2. Square each difference and add.
    (3)ยฒ + (4)ยฒ = 25
  3. 3. Take the square root.
    d = โˆš25 = 5

Computes the straight-line (Euclidean) distance and midpoint between two points using the distance formula. Coordinates are unitless - the result is in the same units as your inputs.

โœ…

Last updated June 2026

Method: Uses the Euclidean distance formula derived from the Pythagorean theorem, d = √((x₂−x₁)² + (y₂−y₁)²), extended with a z-term in 3D. The midpoint averages each coordinate.

Included: 2D and 3D straight-line distance, the midpoint of the two points, the exact radical value, and a full step-by-step breakdown of every difference, square and sum.

Not included: Curved-surface (great-circle/haversine) distance for latitude and longitude, road or travel distance, and Manhattan/taxicab distance. This tool measures flat Euclidean distance only.

Distance calculator: everything you need to know

The straight-line distance between the points (1, 2) and (4, 6) is exactly 5. That clean answer is not a coincidence - it is the famous 3-4-5 right triangle hiding inside the coordinate plane. The horizontal gap is 3, the vertical gap is 4, and the distance you actually want is the hypotenuse, 5. This distance calculator automates that reasoning for any two points, in two or three dimensions, and shows every step so you can see exactly how the number is built.

The distance formula

The distance between two points is the length of the straight line segment that connects them. In two dimensions, the formula is:

d = √((x₂ − x₁)² + (y₂ − y₁)²)

In three dimensions you simply add a term for the third axis:

d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)

Here (x₁, y₁) is the first point, (x₂, y₂) is the second point, and the differences x₂ − x₁ and y₂ − y₁ are the horizontal and vertical gaps between them. Squaring each difference removes any negative signs, so the order of the points never changes the answer.

Where it comes from: the Pythagorean theorem

The distance formula is the Pythagorean theorem in disguise. Drop the two points onto a grid and connect them with a straight line. The horizontal difference and the vertical difference form the two legs of a right triangle, and the distance you want is the hypotenuse. Since leg² + leg² = hypotenuse², the distance is the square root of the sum of the squared legs. The 3D version just stacks one more right triangle into the depth axis. Understanding this connection means you never have to memorize the formula - you can rebuild it from a triangle every time. If you want to solve for a missing leg instead of the hypotenuse, the Pythagorean Theorem Calculator rearranges the same relationship.

How to use this distance calculator

You only need the coordinates of two points to get a complete answer. Work through the fields in order:

  1. Choose 2D or 3D: use the toggle to pick a flat plane (x, y) or space (x, y, z). The third coordinate boxes appear only in 3D mode.
  2. Enter Point A: type the x₁ and y₁ values (and z₁ in 3D) for your first point. Negative numbers and decimals are fine.
  3. Enter Point B: type the x₂ and y₂ values (and z₂ in 3D) for your second point.
  4. Read the result: the large number is the distance, the card beside it shows the exact radical value and the midpoint, and the step-by-step box shows every difference, square and sum.

The result updates instantly as you type. If any required coordinate is blank or not a number, the calculator shows a prompt instead of a misleading answer.

A worked example, step by step

Take the points (2, 3) and (7, 15):

  • Differences: Δx = 7 − 2 = 5, and Δy = 15 − 3 = 12.
  • Square and add: 5² + 12² = 25 + 144 = 169.
  • Square root: d = √169 = 13.

That is the 5-12-13 right triangle, another whole-number "Pythagorean triple." Most real coordinate pairs are not so tidy - they produce irrational distances like √20 ≈ 4.4721 - but the procedure is always identical.

A second example with negatives

Coordinates are often negative, and that is where sign mistakes creep in. Find the distance between (−3, −1) and (2, −13):

  • Δx = 2 − (−3) = 5 (subtracting a negative adds).
  • Δy = −13 − (−1) = −12.
  • Square and add: 5² + (−12)² = 25 + 144 = 169.
  • Square root: d = √169 = 13.

Notice the squared Δy is positive even though the difference was negative - that is exactly why distance is always non-negative.

A 3D example

For points (1, 2, 2) and (4, 6, 4), add the z-axis term:

  • Differences: Δx = 3, Δy = 4, Δz = 2.
  • Square and add: 3² + 4² + 2² = 9 + 16 + 4 = 29.
  • Square root: d = √29 ≈ 5.385.

The pattern scales to any number of dimensions: square the gap on every axis, add them all, and take the square root.

Finding the midpoint

The midpoint is the point exactly halfway between A and B, and it is even simpler than the distance - just average each coordinate:

M = ((x₁ + x₂) ÷ 2, (y₁ + y₂) ÷ 2)

For (1, 2) and (4, 6) that is ((1+4)/2, (2+6)/2) = (2.5, 4). In 3D you average the z-values too. The midpoint is what you need for the center of a line segment, the center of a circle from two endpoints of a diameter, or the balance point between two locations.

Who this calculator is for

The distance formula shows up far beyond the geometry classroom:

  • Students checking homework on coordinate geometry, vectors, and the Pythagorean theorem.
  • Teachers and tutors generating worked examples with clean, verifiable steps.
  • Game and graphics developers measuring how far apart two sprites or 3D objects are.
  • Designers and CAD users finding the gap between two points on a layout or drawing.
  • Data and ML practitioners who use Euclidean distance for clustering and nearest-neighbor methods.
  • Anyone who needs the straight-line gap between two coordinates without re-deriving the algebra.

Perfect squares reference

Recognizing perfect squares makes the final square-root step instant when a distance happens to be a whole number. Keep this table handy:

n n
11981
2410100
3911121
41612144
52513169
63614196
74915225
86420400

When the sum of the squared differences lands on one of these values, the distance is the whole number on the left. Otherwise, the answer is an irrational number and you round at the end.

Common Pythagorean triples

A few coordinate gaps produce exact whole-number distances. Spotting them saves time and confirms your arithmetic:

  • 3, 4, 5 - gaps of 3 and 4 give a distance of 5.
  • 5, 12, 13 - gaps of 5 and 12 give a distance of 13.
  • 8, 15, 17 - gaps of 8 and 15 give a distance of 17.
  • 7, 24, 25 - gaps of 7 and 24 give a distance of 25.

Any multiple works too (6-8-10, 9-12-15), so if your differences are a scaled triple, the distance is a whole number.

Key terms explained

  • Coordinate: a number locating a point along one axis. A 2D point has two (x, y); a 3D point has three (x, y, z).
  • Euclidean distance: the ordinary straight-line distance "as the crow flies," the kind this calculator computes.
  • Midpoint: the point exactly halfway between two points, found by averaging each coordinate.
  • Hypotenuse: the longest side of a right triangle, opposite the right angle - which is what the distance represents.
  • Radical / square root: the √ symbol; an exact distance is often left in radical form (like √20) rather than rounded.
  • Pythagorean triple: three whole numbers a, b, c where a² + b² = c², producing a whole-number distance.

Tips for getting it right

  • Subtract consistently: always do Point B minus Point A for every axis so your signs stay aligned, even though the final answer is unaffected.
  • Square before you add: a frequent error is adding the differences first and then squaring. Square each difference individually, then sum.
  • Keep one unit: every coordinate must be in the same unit, or the distance is meaningless.
  • Round only at the end: carry full precision through the steps and round the final distance to avoid compounding errors.
  • Leave it exact when asked: if a problem wants an exact answer, report the radical (such as √29) instead of a rounded decimal.

Distance on a map is different

It is tempting to plug latitude and longitude into the distance formula, but those coordinates sit on a curved sphere, not a flat plane, so the result will be wrong over any meaningful distance. Map and GPS distances use the haversine or great-circle formula, which accounts for the Earth's curvature. Likewise, the distance you would actually walk or drive (the "Manhattan" or road distance) follows a path, not a straight line. Use this calculator for flat coordinate geometry; reach for a dedicated geographic tool when your points are real-world locations.

Euclidean vs. other distance metrics

The straight-line distance this calculator returns is called Euclidean distance, but it is not the only way to measure how far apart two points are. Which one you want depends entirely on how movement actually happens between the points:

  • Euclidean (straight line): √(Δx² + Δy²) - the shortest possible path, "as the crow flies." This is the default and what the calculator computes.
  • Manhattan (taxicab): |Δx| + |Δy| - the distance you travel along a grid of streets, where you cannot cut diagonally through buildings. It is always greater than or equal to the Euclidean distance.
  • Chebyshev (chessboard): max(|Δx|, |Δy|) - the number of moves a king takes on a chessboard, where a diagonal step counts the same as a straight one.

For the points (1, 2) and (4, 6), the Euclidean distance is 5, the Manhattan distance is |3| + |4| = 7, and the Chebyshev distance is max(3, 4) = 4. All three describe the "same" two points, yet give different numbers because they model different kinds of travel. When people say "the distance," they almost always mean the Euclidean value - but if your context is a street grid or a tile-based game, one of the others may be the honest answer.

Distance from the origin and vector magnitude

A special and very common case is the distance from the origin (0, 0) to a point. Because x₁ and y₁ are both zero, the formula collapses to d = √(x² + y²). That value is also the magnitude (or length) of the position vector pointing to (x, y), which is why distance and vector length are really the same calculation wearing two different names. For the point (3, 4), the distance from the origin is √(9 + 16) = 5, and the vector ⟨3, 4⟩ has a magnitude of 5. In physics this is how you turn the x- and y-components of a velocity or force into a single overall size, and in 3D you simply add the z-component: √(x² + y² + z²). If you ever need the length of a single vector, set Point A to the origin in the calculator above and enter the vector's components as Point B.

Real-world uses of the distance formula

Coordinate distance is not just a textbook exercise - it quietly powers a surprising amount of everyday software and design work:

  • Video games: deciding whether an enemy is close enough to attack, whether two objects collided, or how far a projectile has traveled all reduce to a distance check between coordinates.
  • Computer graphics and CAD: measuring the gap between two anchor points, sizing a line, or snapping objects to a grid uses the same √(Δx² + Δy²) under the hood.
  • Machine learning: clustering algorithms like k-means and nearest-neighbor classifiers measure how "similar" two data points are using Euclidean distance across many feature axes.
  • Robotics and navigation: a robot estimating how far it is from a target waypoint on a flat floor plan computes a straight-line distance between coordinates.
  • Sports analytics: tracking how far a player ran between two positions on a pitch, mapped to x-y coordinates, is a direct application of the formula.

In every one of these cases the underlying math is identical to the worked examples above; only the meaning of the coordinates changes.

Exact vs. rounded answers

Most real coordinate pairs do not land on a Pythagorean triple, so the distance is an irrational number - a decimal that never ends or repeats, like √20 = 4.47213595… There are two correct ways to report such a result, and which you choose depends on the task. The exact form leaves the answer as a radical, such as √20 (or its simplified version 2√5), and is what teachers usually want on a geometry test because it carries no rounding error. The approximate form rounds the decimal to a sensible number of places, such as 4.47, and is what you want for a measurement, a screen position, or anything physical. The golden rule is to round only once, at the very end: if you round the squared differences or the intermediate sum, the small errors compound and your final distance can be noticeably off. Carry full precision through every step and apply rounding only to the last number you report.

Related concepts

The distance formula sits at the center of a small family of coordinate-geometry tools. The midpoint formula (built into this calculator) finds the center of a segment, and the dedicated Midpoint Calculator isolates that step. The slope formula uses the same Δy and Δx to describe a line's steepness - the Slope Calculator turns those gaps into rise-over-run instead of a length. The Pythagorean Theorem Calculator underlies all of them, and the final square-root step is what the Square Root Calculator handles when the sum of squares is not a perfect square. Vector magnitude is just the distance from the origin (0, 0) to a point. Master one and the others fall into place, because they all measure the same right-triangle relationships in slightly different ways.

โš ๏ธ Common mistakes & edge cases

Adding the differences before squaring

(Δx + Δy)² is not the same as Δx² + Δy². You must square each difference first, then add. For gaps of 3 and 4 the right answer is √(9 + 16) = 5, not √(3 + 4)² = 7.

Mishandling negative coordinates

Subtracting a negative adds. With points at −3 and 2, Δx = 2 − (−3) = 5, not −1. A dropped sign here is the single most common source of wrong distances.

Forgetting the square root

The sum of squared differences is the distance squared, not the distance. You must take the square root at the end. Stopping at 25 instead of √25 = 5 reports the wrong number.

Using lat/long as if the plane were flat

Latitude and longitude lie on a sphere. The distance formula treats them as flat (x, y) values and gives a meaningless number for real map locations. Use the haversine/great-circle formula for geographic distance.

Note: This calculator measures straight-line (Euclidean) distance on a flat plane or in 3D space. Coordinates are unitless - the answer is in whatever unit your inputs use. Results are provided for educational purposes; verify any value used for academic, engineering or professional work.

❓ Frequently asked questions

What is the distance formula?

The distance formula gives the straight-line distance between two points. In 2D it is d = sqrt((x2 - x1)^2 + (y2 - y1)^2). In 3D you add the z-axis: d = sqrt((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2). It comes directly from the Pythagorean theorem, where the distance is the hypotenuse of a right triangle formed by the horizontal and vertical gaps between the points.

How do I calculate the distance between two points?

Subtract the x-coordinates to get the horizontal gap, subtract the y-coordinates to get the vertical gap, square both differences, add them together, then take the square root of that sum. For example, the distance between (1, 2) and (4, 6) is sqrt((4-1)^2 + (6-2)^2) = sqrt(9 + 16) = sqrt(25) = 5.

How is the distance formula related to the Pythagorean theorem?

They are the same idea. The horizontal difference (x2 - x1) and the vertical difference (y2 - y1) form the two legs of a right triangle, and the distance between the points is the hypotenuse. The Pythagorean theorem says leg^2 + leg^2 = hypotenuse^2, so taking the square root of (dx^2 + dy^2) gives the distance.

Does the order of the points matter?

No. The distance from A to B is always the same as from B to A. Each difference is squared, and squaring removes the sign, so it does not matter whether you subtract A from B or B from A. (x2 - x1)^2 equals (x1 - x2)^2 either way.

How do I find the midpoint between two points?

Average each coordinate. The midpoint is ((x1 + x2)/2, (y1 + y2)/2), and in 3D you also average the z-values. For (1, 2) and (4, 6) the midpoint is ((1+4)/2, (2+6)/2) = (2.5, 4). The midpoint always lies exactly halfway along the straight line connecting the two points.

Can the distance ever be negative?

No. Distance is always zero or positive because each difference is squared (making it non-negative) before the square root is taken. The only way to get a distance of zero is when the two points are identical. If you ever compute a negative distance, you have made a sign or square-root error.

What is the difference between 2D and 3D distance?

2D distance measures the gap between points on a flat plane using only x and y coordinates. 3D distance adds a third axis (z) for depth or height, so it measures the gap between points in space. The formula is the same pattern - square the differences on every axis, add them, and take the square root - just with one more term in 3D.

What units does the distance calculator use?

The calculator is unit-agnostic: the distance comes out in the same units as the coordinates you enter. If your x and y values are in meters, the distance is in meters; if they are in pixels, the distance is in pixels. Mixing units (for example x in meters and y in feet) will give a meaningless result, so keep every coordinate in the same unit.

Does the distance formula work for map locations like latitude and longitude?

Not directly. The distance formula assumes a flat plane, but latitude and longitude lie on a curved sphere. Over short distances the error is small, but for accurate map distances you need the haversine formula or great-circle distance, which account for the Earth's curvature. Use this calculator for flat coordinate geometry, not GPS coordinates.

How many decimal places should I keep in the answer?

Keep enough to match the precision of your inputs. If your coordinates are whole numbers, two to four decimal places of the distance is plenty. Many distances are irrational (like sqrt(2) = 1.41421...), so they never terminate - round only at the final step to avoid compounding rounding errors, and report the exact radical form (such as sqrt(20)) when an exact answer is required.

What is the difference between Euclidean and Manhattan distance?

Euclidean distance is the straight-line gap, sqrt(dx^2 + dy^2) - the shortest possible path. Manhattan (taxicab) distance is |dx| + |dy|, the distance you travel along a grid of streets where you cannot cut diagonally. For (1, 2) and (4, 6) the Euclidean distance is 5 but the Manhattan distance is 3 + 4 = 7. This calculator computes Euclidean distance; use Manhattan distance only when movement is restricted to a grid.

Is the distance from the origin the same as a vector's magnitude?

Yes. The distance from the origin (0, 0) to a point (x, y) is sqrt(x^2 + y^2), which is exactly the magnitude (length) of the vector pointing to that point. For (3, 4) both the distance from the origin and the vector magnitude are 5. To find a vector's length with this tool, set Point A to (0, 0) and enter the vector's components as Point B.

How do I find the distance in 4 or more dimensions?

The pattern never changes: subtract each coordinate, square every difference, add them all together, and take the square root of the sum. A 4D distance is sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2 + (w2-w1)^2). This is exactly how Euclidean distance works in machine learning, where points can have dozens or hundreds of dimensions. This calculator covers the 2D and 3D cases that come up most often.

๐Ÿ’ก Good to know

It is just the Pythagorean theorem

If you ever forget the distance formula, draw the right triangle. The horizontal and vertical gaps are the legs, and the distance is the hypotenuse - so d = √(leg² + leg²). You can rebuild the formula from a triangle every time.

Distance is never negative

Because every difference is squared before the square root, the result is always zero or positive. A distance of zero means the two points are identical. If you compute a negative distance, recheck your signs and the square root.

Higher dimensions follow the same rule

The formula generalizes: square the gap on every axis, add them all, and take the square root. That is why the 3D version simply adds a z-term, and the same idea powers Euclidean distance in machine learning across many dimensions.

Related Calculators