ToolNimba

๐Ÿ“ 2D Distance Calculator: Distance Between Two Points

Shihab Mia By Shihab Mia ยท Updated 2026-07-09

Point A (x1, y1)
Point B (x2, y2)
Distance (d)
-
Midpoint (M)
-

Enter the coordinates of two points to find the straight-line distance and the midpoint between them.

This 2D distance calculator finds the straight-line distance between two points on a coordinate plane. Enter point A (x1, y1) and point B (x2, y2), and it returns the exact Euclidean distance using the distance formula, plus the midpoint that sits halfway between them. Every calculation is shown step by step, so you can check the working as well as the final answer, which makes it useful for geometry homework, drafting, game and graphics layout, and quick coordinate checks.

What is the Distance Calculator?

A 2D distance calculator measures how far apart two points are on a flat plane, and the distance formula it uses is just the Pythagorean theorem rewritten for coordinates. If you draw the horizontal gap (x2 - x1) and the vertical gap (y2 - y1) between two points, they form the two legs of a right triangle, and the straight line joining the points is the hypotenuse. The theorem says the hypotenuse squared equals the sum of the squares of the legs, so the distance d satisfies d^2 = (x2 - x1)^2 + (y2 - y1)^2, and taking the square root gives d = sqrt((x2 - x1)^2 + (y2 - y1)^2).

This is the Euclidean distance, the everyday notion of how far apart two locations are in a straight line. Because each difference is squared before being added, the result is always zero or positive, and the order of the points does not matter: the distance from A to B equals the distance from B to A. Negative coordinates are perfectly fine, since squaring removes the sign. The distance is zero only when the two points are identical, and it grows as either the horizontal or the vertical gap grows.

The units of the answer are simply whatever units your coordinates use. If x and y are measured in metres, the distance is in metres; if they are pixels on a screen, the distance is in pixels. The calculator does not assume any particular unit, so the same tool works for a graph in a textbook, a CAD drawing, or a sprite position in a game engine. When the result is not a whole number, it is an irrational value like sqrt(2) or sqrt(5), which is why many answers are shown as long decimals.

The midpoint is a separate but closely related result: it is the point exactly halfway along the segment, found by averaging the two x values and the two y values, M = ((x1 + x2) / 2, (y1 + y2) / 2). The midpoint always lies on the line between the two points and is the same distance from each of them, which is why it appears in geometry, computer graphics, and mapping whenever you need a centre point, a bisector, or a label position halfway along a line.

The same idea extends naturally to three dimensions by adding a (z2 - z1)^2 term inside the square root, giving d = sqrt((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2). This 2D distance calculator focuses on the x-y plane, which covers the vast majority of school, engineering, and screen-layout problems, but knowing that the pattern continues into higher dimensions helps explain why the formula looks the way it does. One thing to keep in mind is that Euclidean distance measures a straight line only. If movement is restricted to a grid, where you can go along and up but not diagonally, you need the Manhattan (taxicab) distance instead, which adds the absolute gaps: |x2 - x1| + |y2 - y1|.

When to use it

  • Checking geometry and coordinate homework where you need both the distance and the midpoint of a line segment.
  • Measuring the straight-line gap between two plotted points on a chart, graph, or grid.
  • Finding how far apart two pixels or screen positions are when laying out a game, UI, or graphic.
  • Locating the centre point between two coordinates, for example to place a label or a marker halfway along a line.
  • Verifying survey, drafting, or CAD dimensions where points are given as (x, y) coordinates.
  • Calculating the length of a vector or the radius of a circle from its centre to a point on its edge.

How to use the Distance Calculator

  1. Enter the x and y coordinates of the first point, point A (x1, y1).
  2. Enter the x and y coordinates of the second point, point B (x2, y2).
  3. Read off the distance and the midpoint, which update as you type.
  4. Open the step-by-step panel to see each part of the calculation.
  5. Use a sample button to load a worked example, or clear the fields to start again.

Formula & method

d = √((x2 - x1)2 + (y2 - y1)2), and the midpoint M = ((x1 + x2) ÷ 2, (y1 + y2) ÷ 2).
A (x1, y1)B (x2, y2)horizontal gap = x2 - x1vertical gap = y2 - y1distance dd = sqrt( (x2 - x1)^2 + (y2 - y1)^2 )

Worked examples

Find the distance and midpoint between A(1, 2) and B(4, 6).

  1. Horizontal gap: x2 - x1 = 4 - 1 = 3
  2. Vertical gap: y2 - y1 = 6 - 2 = 4
  3. Square and add: 3^2 + 4^2 = 9 + 16 = 25
  4. Distance: d = sqrt(25) = 5
  5. Midpoint: ((1 + 4) / 2, (2 + 6) / 2) = (2.5, 4)

Result: Distance = 5 units, midpoint = (2.5, 4).

Find the distance and midpoint between A(-2, 3) and B(3, -9).

  1. Horizontal gap: x2 - x1 = 3 - (-2) = 5
  2. Vertical gap: y2 - y1 = -9 - 3 = -12
  3. Square and add: 5^2 + (-12)^2 = 25 + 144 = 169
  4. Distance: d = sqrt(169) = 13
  5. Midpoint: ((-2 + 3) / 2, (3 + (-9)) / 2) = (0.5, -3)

Result: Distance = 13 units, midpoint = (0.5, -3).

Find the distance and midpoint between A(0, 0) and B(1, 1).

  1. Horizontal gap: x2 - x1 = 1 - 0 = 1
  2. Vertical gap: y2 - y1 = 1 - 0 = 1
  3. Square and add: 1^2 + 1^2 = 1 + 1 = 2
  4. Distance: d = sqrt(2) = 1.414214 (an irrational number)
  5. Midpoint: ((0 + 1) / 2, (0 + 1) / 2) = (0.5, 0.5)

Result: Distance = about 1.414214 units, midpoint = (0.5, 0.5).

Worked distances and midpoints for common point pairs

Point APoint BDistanceMidpoint
(0, 0)(3, 4)5(1.5, 2)
(1, 2)(4, 6)5(2.5, 4)
(0, 0)(5, 5)7.071068(2.5, 2.5)
(-2, 3)(3, -9)13(0.5, -3)
(2, 2)(2, 9)7(2, 5.5)
(0, 0)(1, 1)1.414214(0.5, 0.5)

Pythagorean point pairs that give whole-number distances

Horizontal gap (x2 - x1)Vertical gap (y2 - y1)Distance d
345
6810
51213
81517
72425
202129

Euclidean vs Manhattan distance for the same point pairs

Point APoint BEuclidean (straight line)Manhattan (grid path)
(0, 0)(3, 4)57
(0, 0)(1, 1)1.4142142
(1, 1)(4, 5)57
(-2, 3)(3, -9)1317

Common mistakes to avoid

  • Forgetting to square the differences. The distance is not (x2 - x1) + (y2 - y1). You must square each difference, add them, then take the square root. Adding the raw gaps gives a wrong, larger answer except in trivial cases.
  • Mishandling negative coordinates. Subtracting a negative coordinate flips the sign, so x2 - x1 with x1 = -2 becomes x2 + 2. Because the gap is squared anyway, its sign never changes the distance, but getting the subtraction wrong does.
  • Mixing up the distance and midpoint formulas. Distance squares and roots the differences, while the midpoint just averages the coordinates. Do not square anything when finding the midpoint. Simply add each pair of coordinates and divide by two.
  • Taking the square root of each term separately. You cannot write d as sqrt((x2 - x1)^2) + sqrt((y2 - y1)^2), which would just give |x2 - x1| + |y2 - y1|. The square root applies to the whole sum, after the squared terms are added together.
  • Confusing Euclidean distance with grid distance. The distance formula gives the straight-line (Euclidean) distance. If you can only move along a grid, the relevant measure is the Manhattan distance, |x2 - x1| + |y2 - y1|, which is usually larger.
  • Rounding too early. Many distances are irrational, like sqrt(2) or sqrt(5). Rounding intermediate square roots before the final step introduces error. Keep full precision until the last line, then round the final answer.

Glossary

Coordinate
A pair of numbers (x, y) that fixes the position of a point on the plane.
Euclidean distance
The ordinary straight-line distance between two points, the length of the segment joining them.
Distance formula
d = sqrt((x2 - x1)^2 + (y2 - y1)^2), the Pythagorean theorem applied to coordinates.
Midpoint
The point exactly halfway between two points, found by averaging their x values and their y values.
Pythagorean theorem
For a right triangle, the square of the hypotenuse equals the sum of the squares of the other two sides.
Hypotenuse
The longest side of a right triangle, opposite the right angle. In the distance formula it represents the distance itself.
Manhattan distance
The grid or taxicab distance, |x2 - x1| + |y2 - y1|, the length of a path that moves only horizontally and vertically.
Irrational number
A number that cannot be written as a simple fraction, such as sqrt(2). Many exact distances are irrational and shown as long decimals.

Frequently asked questions

What is the distance formula for two points?

The distance between two points (x1, y1) and (x2, y2) is d = sqrt((x2 - x1)^2 + (y2 - y1)^2). It comes directly from the Pythagorean theorem: the horizontal and vertical gaps are the legs of a right triangle, and the distance is the hypotenuse.

How do I calculate the distance between two points?

Subtract the x values to get the horizontal gap and the y values to get the vertical gap, square each gap, add them, then take the square root. For example, from (1, 2) to (4, 6) the gaps are 3 and 4, so d = sqrt(9 + 16) = sqrt(25) = 5.

Does the order of the points matter?

No. Because each difference is squared, swapping the points only changes the sign of the gaps, which disappears when you square them. The distance from A to B is always the same as the distance from B to A.

How is the midpoint between two points calculated?

The midpoint is M = ((x1 + x2) / 2, (y1 + y2) / 2). You average the two x coordinates and the two y coordinates. The result is the point exactly halfway along the segment and the same distance from each end.

Can I use negative coordinates in a 2D distance calculator?

Yes. Negative coordinates work fine. Just be careful with the subtraction, since subtracting a negative number adds it. The squaring step means the sign of each gap never affects the final distance.

What is the difference between Euclidean and Manhattan distance?

Euclidean distance is the straight-line distance, sqrt((x2 - x1)^2 + (y2 - y1)^2). Manhattan distance is the grid path, |x2 - x1| + |y2 - y1|, the total of the horizontal and vertical moves. Manhattan distance is equal to or larger than Euclidean distance, and this tool calculates the Euclidean value.

Why is the distance sometimes a long decimal?

When the sum of the squared gaps is not a perfect square, the square root is irrational, like sqrt(2) = 1.414214 or sqrt(5) = 2.236068. These cannot be written as exact decimals, so the calculator shows a rounded value with several decimal places.

Does this calculator work in three dimensions?

This tool covers the two-dimensional x-y plane. In three dimensions you add a (z2 - z1)^2 term inside the square root, giving d = sqrt((x2 - x1)^2 + (y2 - y1)^2 + (z2 - z1)^2), but the idea is exactly the same.

What units does the distance come out in?

The answer is in whatever units your coordinates use. If x and y are in metres, the distance is in metres; if they are pixels, the distance is in pixels. The calculator does not assume any unit, so it applies to graphs, maps, drawings, and screens alike.

How do I find the distance from the origin to a point?

The origin is (0, 0), so the distance to a point (x, y) simplifies to d = sqrt(x^2 + y^2). For example, the distance from (0, 0) to (3, 4) is sqrt(9 + 16) = sqrt(25) = 5. This value is also the length of the position vector to that point.