Skip to content

Distance formula calculator

Enter two points on a coordinate plane to get the distance between them, the midpoint, the slope, the angle from the x-axis and the equation of the line through both points.

  • Free, no limits
  • No sign-up
Everything happens in your browser; your data is never uploaded.
  • ✓ Free
  • ✓ No sign-up
  • ✓ Nothing uploaded

Next step

What to do next

How to use it

  1. Enter x₁ and y₁ for point A.
  2. Enter x₂ and y₂ for point B.
  3. Read the distance and midpoint.
  4. Check the slope and the line equation.
Try it now

The distance formula

The distance between points (x₁, y₁) and (x₂, y₂) comes from the Pythagorean theorem:

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

Example: A(1, 2) and B(4, 6).

  • Δx = 4 − 1 = 3, Δy = 6 − 2 = 4
  • d = √(9 + 16) = √25 = 5

The horizontal and vertical changes are the legs of a right triangle, and the distance is its hypotenuse. The calculator shows this working along with every result. It runs entirely in your browser.

Midpoint

The midpoint is the average of the coordinates:

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

For A(1, 2) and B(4, 6): M = (2.5, 4).

Midpoints are handy for finding the center of a segment, the center of a circle from the ends of its diameter, or a fair meeting point on a grid map.

Slope and the equation of the line

Slope: m = (y₂ − y₁) / (x₂ − x₁), the rise over the run. For our points, m = 4 / 3 ≈ 1.3333.

Slope-intercept form: y = mx + b, where b = y₁ − m × x₁. Here b = 2 − 4/3 ≈ 0.6667, so y = 1.3333x + 0.6667.

Angle from the x-axis: arctan(m) ≈ 53.13°.

Special cases: if the two y values are equal, the line is horizontal (slope 0, y = constant). If the x values are equal, the line is vertical, the slope is undefined and the equation is x = constant.

Where it is used

  • Geometry homework: side lengths, perimeters and checking whether a shape is a parallelogram or a right triangle.
  • Maps and games: straight-line distance between grid positions.
  • Graphic design and CAD: distances between points in pixel or drawing coordinates.
  • Physics: displacement between two positions.

On a city street grid, the walking distance is |Δx| + |Δy| (here 7 blocks) rather than the straight-line 5, because you cannot cut through buildings.

Tips and common mistakes

  • Order does not matter for distance: squaring removes the sign. For slope, keep the same order in the numerator and denominator.
  • Watch negative coordinates. 2 − (−3) = 5, not −1.
  • Units: the distance is in the same unit as the coordinates. On real maps, latitude and longitude are not a flat grid, so this formula is only an approximation over short distances.
  • Exactly equal points give a distance of 0 and no line.

To solve the triangle formed by three points, use the triangle calculator.

Extending to three dimensions

In 3D space, add the third coordinate: d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²). For example, the diagonal of a box 3 × 4 × 12 is √(9 + 16 + 144) = 13. This calculator works in two dimensions; for 3D you can apply the formula with the square root calculator.

The midpoint idea also extends: average each coordinate separately.

Checking a right angle: three points form a right triangle if the squared distances satisfy a² + b² = c². Find the three distances here, then compare. Two lines are perpendicular when the product of their slopes is −1, as with slopes 2 and −1/2. Parallel lines have equal slopes, so you can also check whether opposite sides of a four-sided shape are parallel. All of this runs in your browser as you type.

Frequently asked questions

What is the distance formula?

d = √((x₂ − x₁)² + (y₂ − y₁)²). It is the Pythagorean theorem applied to the coordinate plane.

How do I find the midpoint?

Average the x-coordinates and the y-coordinates: ((x₁ + x₂)/2, (y₁ + y₂)/2).

How do I find the slope between two points?

Divide the change in y by the change in x: (y₂ − y₁) / (x₂ − x₁).

What if the line is vertical?

The slope is undefined, and the equation is x = constant. The calculator shows this.

Can I use negative or decimal coordinates?

Yes. Any real numbers work.

Last updated: November 12, 2026

Recommended

Similar tools

If Distance formula calculator helped, you may need these too.

See all in category →

People also use