Distance Formula Calculator

Find the distance between two points in 2D or 3D with AI-powered step-by-step solutions

Drag & drop or click to add images or PDF

Math Input
Distance from (1, 2) to (4, 6)
Distance between (-3, 5) and (2, -7)
Distance from (1, 2, 3) to (4, 6, 8)
Distance between origin and (5, 12)

What is the Distance Formula?

The distance formula computes the straight-line distance between two points in coordinate space. It's a direct consequence of the Pythagorean theorem applied to the right triangle formed by the horizontal and vertical separation between the points.

2D form — for points P1=(x1,y1)P_1 = (x_1, y_1) and P2=(x2,y2)P_2 = (x_2, y_2):

d=(x2x1)2+(y2y1)2d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}

3D form — for points (x1,y1,z1)(x_1, y_1, z_1) and (x2,y2,z2)(x_2, y_2, z_2):

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

nn-dimensional form (Euclidean distance):

d=i=1n(biai)2d = \sqrt{\sum_{i=1}^n (b_i - a_i)^2}

This generalizes naturally to any number of dimensions, which is why it's the workhorse 'distance' notion in physics, statistics, and machine learning.

How to Use the Distance Formula

Step-by-Step

  1. Label the points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2). Either assignment works — the formula is symmetric.
  2. Compute differences: Δx=x2x1\Delta x = x_2 - x_1, Δy=y2y1\Delta y = y_2 - y_1.
  3. Square them: (Δx)2(\Delta x)^2 and (Δy)2(\Delta y)^2.
  4. Sum: (Δx)2+(Δy)2(\Delta x)^2 + (\Delta y)^2.
  5. Take the square root: d=sumd = \sqrt{\text{sum}}.
  6. Simplify the radical if possible (e.g., 50=52\sqrt{50} = 5\sqrt{2}).

Geometric Derivation

Draw a horizontal segment from (x1,y1)(x_1, y_1) to (x2,y1)(x_2, y_1) — length x2x1|x_2 - x_1|.
Draw a vertical segment from (x2,y1)(x_2, y_1) to (x2,y2)(x_2, y_2) — length y2y1|y_2 - y_1|.
The original segment is the hypotenuse of a right triangle with these two legs, so by the Pythagorean theorem:

d2=(x2x1)2+(y2y1)2d^2 = (x_2 - x_1)^2 + (y_2 - y_1)^2

Taking square roots gives the distance formula. The absolute values aren't needed because squaring removes the sign.

Related Formulas

  • Midpoint: M=(x1+x22,y1+y22)M = \left(\frac{x_1 + x_2}{2}, \frac{y_1 + y_2}{2}\right) — the average of the coordinates.
  • Slope: m=y2y1x2x1m = \frac{y_2 - y_1}{x_2 - x_1} — uses the same differences as the distance formula.
  • Distance from point to origin: d=x2+y2d = \sqrt{x^2 + y^2} (special case with (x1,y1)=(0,0)(x_1, y_1) = (0, 0)).

Manhattan / Taxicab Distance (For Comparison)

Note that the formula above is Euclidean distance. Manhattan distance x2x1+y2y1|x_2 - x_1| + |y_2 - y_1| measures travel on a grid (no diagonals). They are different metrics — make sure you know which one your problem wants.

Common Mistakes to Avoid

  • Forgetting to square: d(x2x1)+(y2y1)d \ne (x_2 - x_1) + (y_2 - y_1). The squares (and the square root) are essential.
  • Sign errors: (x2x1)2=(x1x2)2(x_2 - x_1)^2 = (x_1 - x_2)^2, so subtraction order doesn't matter — but only because of the square. Don't drop the square because you 'see' the difference.
  • Forgetting to take the square root: (x2x1)2+(y2y1)2(x_2 - x_1)^2 + (y_2 - y_1)^2 is d2d^2, not dd. Many students stop one step early.
  • Not simplifying the radical: 8=22\sqrt{8} = 2\sqrt{2}. Leaving as 8\sqrt{8} is technically correct but usually marked down on exams.
  • Mixing 2D and 3D: If your problem is in 3D, include the (z2z1)2(z_2 - z_1)^2 term. If 2D, don't invent a zz term.

Examples

Step 1: Δx=41=3\Delta x = 4 - 1 = 3, Δy=62=4\Delta y = 6 - 2 = 4
Step 2: Squares: 32=93^2 = 9, 42=164^2 = 16
Step 3: Sum: 9+16=259 + 16 = 25
Step 4: Square root: 25=5\sqrt{25} = 5
Answer: d=5d = 5

Step 1: Δx=2(3)=5\Delta x = 2 - (-3) = 5, Δy=75=12\Delta y = -7 - 5 = -12
Step 2: Squares: 52=255^2 = 25, (12)2=144(-12)^2 = 144
Step 3: Sum: 25+144=16925 + 144 = 169
Step 4: Square root: 169=13\sqrt{169} = 13
Answer: d=13d = 13

Step 1: Δx=3\Delta x = 3, Δy=4\Delta y = 4, Δz=5\Delta z = 5
Step 2: Squares: 9+16+25=509 + 16 + 25 = 50
Step 3: Distance: 50=527.07\sqrt{50} = 5\sqrt{2} \approx 7.07
Answer: d=527.07d = 5\sqrt{2} \approx 7.07

Frequently Asked Questions

The Pythagorean theorem. The horizontal and vertical separations between two points form the legs of a right triangle, and the straight-line distance is the hypotenuse. Squaring, summing, and taking a square root is exactly the Pythagorean recipe.

No. The formula is symmetric because the differences are squared. (x₂ - x₁)² and (x₁ - x₂)² are equal, so you can label the points either way.

Just add a squared difference for each dimension: d = √(Σ(b_i - a_i)²). This is the Euclidean distance in n-dimensional space, used heavily in machine learning, statistics, and physics.

That's a different problem — use the point-to-line distance formula: d = |Ax₀ + By₀ + C| / √(A² + B²) for line Ax + By + C = 0 and point (x₀, y₀). The basic distance formula only handles point-to-point.

Related Solvers

Pythagorean Theorem CalculatorArea CalculatorLinear Equation Calculator
Try AI-Math for Free

Get step-by-step solutions to any math problem. Upload a photo or type your question.

Start Solving