Math

Distance between two points calculator (2D)

Settings
Reset
Share
Save
Embed
Report a bug

Share calculator

Add our free calculator to your website

Please enter a valid URL. Only HTTPS URLs are supported.


Use as default values for the embed calculator what is currently in input fields of the calculator on the page.


Input border focus color, switchbox checked color, select item hover color etc.


Please agree to the Terms of Use.

Preview

Save calculator

Calculator Settings

Please enter a value within the allowed range.

Please enter a value within the allowed range.

Please enter a value within the allowed range.

Please enter a value within the allowed range.

Share calculator

What is a 2D distance calculator?

A 2D distance calculator finds the straight-line distance between two points on a flat plane. Each point is described by an x-coordinate (its horizontal position) and a y-coordinate (its vertical position). The distance between the two points is the length of the line segment that connects them — the shortest possible path between them in the plane.

This calculator takes the coordinates of point 1, written as (x1,y1)(x_1, y_1), and the coordinates of point 2, written as (x2,y2)(x_2, y_2), and returns the distance dd. It works for any pair of real numbers, including negative and decimal values, and you can mix and match length units for each coordinate.

Key concepts

  • Point — a location in the plane, described by an ordered pair (x,y)(x, y).
  • Coordinate axes — two perpendicular number lines (x horizontal, y vertical) that meet at the origin (0,0)(0, 0).
  • Euclidean distance — the ordinary “as the crow flies” distance, measured along a straight line.
  • Right triangle — the difference along x and the difference along y form the two legs of a right triangle whose hypotenuse is the distance between the points.

How does the calculator work?

The distance between two points in the plane is a direct application of the Pythagorean theorem. The horizontal gap between the points is x2x1x_2 - x_1, the vertical gap is y2y1y_2 - y_1, and these two gaps are the legs of a right triangle. The distance is the hypotenuse.

Formula

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

The order of the points does not matter: swapping point 1 and point 2 changes the signs of x2x1x_2 - x_1 and y2y1y_2 - y_1, but those differences are squared, so the result is the same.

Worked examples

Example 1: the classic 3-4-5 triangle

From the origin (0,0)(0, 0) to the point (3,4)(3, 4):

d=(30)2+(40)2=9+16=25=5d = \sqrt{(3 - 0)^2 + (4 - 0)^2} = \sqrt{9 + 16} = \sqrt{25} = 5

Example 2: two points away from the origin

From (1,1)(1, 1) to (4,5)(4, 5):

d=(41)2+(51)2=9+16=25=5d = \sqrt{(4 - 1)^2 + (5 - 1)^2} = \sqrt{9 + 16} = \sqrt{25} = 5

Example 3: a point to itself

If both points coincide at (0,0)(0, 0):

d=(00)2+(00)2=0d = \sqrt{(0 - 0)^2 + (0 - 0)^2} = 0

Example 4: negative coordinates

From (1,1)(-1, -1) to (2,3)(2, 3):

d=(2(1))2+(3(1))2=9+16=25=5d = \sqrt{(2 - (-1))^2 + (3 - (-1))^2} = \sqrt{9 + 16} = \sqrt{25} = 5

Practical uses

  • Geometry and trigonometry — building blocks for finding perimeters of polygons, lengths of diagonals, or sides of triangles in coordinate problems.
  • Computer graphics and games — measuring how far one sprite or object is from another on a 2D screen.
  • Robotics and navigation — calculating how far a robot needs to travel from one waypoint to another on a planar map.
  • Geographic mapping — approximating short distances on a flat map projection.
  • Statistics and machine learning — the Euclidean distance is the basis for many clustering and nearest-neighbour algorithms applied to two-dimensional feature spaces.

Notes

  • The formula assumes a flat (Euclidean) plane. On the surface of the Earth, for longer distances, use a great-circle distance instead.
  • The distance is always non-negative. If you get a negative number, check that you squared the differences.
  • The two points can be given in any order — the distance is symmetric.
  • All coordinates should be expressed in the same length unit; the calculator handles unit conversion automatically when you change a coordinate’s unit.
  • For the 3D version, see the related Pythagorean theorem calculator, which shows the same idea applied to the sides of a right triangle.

FAQs

Does the order of the two points matter?

No. Because the differences x2x1x_2 - x_1 and y2y1y_2 - y_1 are squared in the formula, swapping the labels of the two points gives exactly the same distance.

Can I use negative coordinates?

Yes. Coordinates can be any real numbers — positive, negative, or zero. The formula handles all of them correctly because the squared differences are always non-negative.

What is the relationship with the Pythagorean theorem?

The 2D distance formula is the Pythagorean theorem applied to the right triangle formed by the horizontal and vertical gaps between the two points. The horizontal gap x2x1|x_2 - x_1| and the vertical gap y2y1|y_2 - y_1| are the legs; the distance dd is the hypotenuse.

How do I extend this to three dimensions?

Add a third squared difference for the z-coordinate: d=(x2x1)2+(y2y1)2+(z2z1)2d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}.

What if my two points are on a map?

For short distances, the 2D formula is a reasonable approximation if you treat latitude and longitude (or a projected x-y grid) as planar coordinates. For longer distances on the Earth’s surface, use the haversine or great-circle formula instead.

Report a bug

This field is required.