Distance Formula – Explanation and Examples

Distance FormulaThe distance formula is an equation used to calculate the length of a line segment given its endpoints.

Since the inputs for the distance formula are two points, it can also be used to determine the distance between two points.

The distance formula is used for line segments and points in two-dimensional space. It is a good idea to make sure you have a solid understanding of coordinate geometry before moving on with this subject. It is also a good idea to review the Pythagorean Theorem since we can use it to derive the distance formula.

This topic will cover the following subtopics:

  • What is the Distance Formula?
  • Where did the Formula Come From?
  • Deriving the Formula
  • How to Use the Distance Formula
  • How to Find the Distance Between Two Points

What is the Distance Formula?

If we have two points (x1, y1) and (x2, y2), the distance between them is:


Note that we will get the same answer regardless of which point we choose as (x1, y1) and which we choose as (x2, y2).

The distance formula tells us the length of a line segment with the given points as endpoints. More generally, it tells us the distance between the two given points.

The distance formula may seem complicated and difficult to remember. Actually, however, the easiest way to keep the plus and minus signs and squares and square roots straight is to remember the origins of the formula.

Where Did the Formula Come From?

The distance formula is actually related to the Pythagorean Theorem!


Let’s consider a line segment that starts at the origin and ends at the point (3, 4).


We can then draw lines from (0, 0) to (3, 0) and from (3, 0) to (3, 4).

Pythagorean Theorem

We now have a right triangle! Since the legs of this triangle are precisely horizontal and vertical and since they intersect grid lines, we can just count their lengths. The horizontal line is 3 units, and the vertical line is 4 units.

Then, we know this is a special 3-4-5 triangle, and the length of the horizontal line is 5 units.

But, if we consider how we constructed this triangle, we realize that every line segment can be modeled as the hypotenuse of a right triangle.

Deriving the Formula

Therefore, we can use the Pythagorean Theorem to derive the distance formula.

If the Pythagorean Theorem is a2+b2=c2, where a is the horizontal line and b is the vertical line in this case, then the length of the hypotenuse, c, is:


The length of any horizontal line is the difference between the two x-values in two points. In our initial example, for instance, the difference is 0-3=3 units. Likewise, the length of any vertical line is the difference between the two y-values. Again, in our initial example, the length was 4-0=4 units.

Therefore, we can replace a with x1-x2 and b with y1-y2 to get:


This is the distance formula!

How to Use the Distance Formula

We can use the distance formula to find the length of a line segment or the distance between two points.

First, if we do not already know the coordinates of the line segment’s endpoints or the two points in question, we have to find those.

Recall that the coordinates of a point are simply (x, y), where x and y are real numbers representing the horizontal distance from the origin and the vertical distance from the origin respectively. Negative numbers represent movement left and down, while positive numbers represent movement up and to the right.

Coordinate planes will usually have grid lines representing a fixed interval. This can be 1 unit, 2 units, pi units, 100 units, etc. It can also be different for horizontal and vertical grid lines. Always check the grid line interval length before determining the coordinates of a point.

Then, finally, we can figure out a particular point’s x-coordinate by counting the number of vertical grid lines between it and the origin and then multiplying that number by the grid line interval length. Likewise, the y-coordinate is the number of horizontal grid lines between it and the origin multiplied by the interval length.

How to Find the Distance Between Two Points

Now, pick one of the points to be (x1, y1), and let the other be (x2, y2).

We can determine the distance between these two points by simply plugging the numbers in to the distance formula.

Remember, it doesn’t matter which point you select as (x1, y1) and which point you select as (x2, y2). Since the distance formula involves squaring the difference, it doesn’t matter if we have x1-x2 or x2-x1 because (x1-x2)2=(x2-x1)2. In fact, expanding both equations gives us x12+x22-2x1x2. The same is true for y1 and y2.

Note that, in the special case where one of the points is the origin, the distance formula simplifies to:



In this section, we will go over common problems involving the distance formula as well as the step-by-step solutions to these problems.

Example 1

Find the coordinates of the vertices of the triangle shown. Then, use the distance formula to find the perimeter of the triangle.

Example 1 Graph 1

Example 1 Solution

Because this is a right triangle, we could actually just find the lengths of the horizontal and vertical lines. Then, we could find the length of the hypotenuse using the Pythagorean Theorem. However, we will use the distance formula in this solution to get some practice with it.

Let’s consider the horizontal line first. Let the origin be (x1, y1) and let the point (12, 0) be (x2, y2). Then, plugging in the values, we have:


This simplifies as:



Finally, we know D=√(144)=12. Therefore, the length of the horizontal line is 12 units.

Likewise, if the origin is (x1, y1) and the point (0, -9) is (x2, y2), we have:



Thus, we can conclude that D=√(81)=9 units, and this is the length of the vertical line.

Finally, let (12, 0) be (x1, y1) and let (0, -9) be (x2, y2). The length of the hypotenuse is therefore:



We can further simplify this to:


Therefore, the lengths are 8 units, 9 units, and 15 units. The perimeter of the triangle is 8+9+15=32.

What if we had just found the length of the horizontal and vertical lines and then used the Pythagorean Theorem? We would have had 82+92=64+91=225. The square root of 225 is 15, so either way works for getting the answer.

Example 2

Compare the lengths of four line segments with a common endpoint at the origin. Line A ends at (7, 16), line B ends at (-7, 16), line C ends at (-7, -16), and line D ends at (7, -16).

Example 2 Solution

A quick sketch graphically shows us that these four segments all have the same length.

Example 2 Graph

Let’s use the distance formula and see if we get the same results.

Line A:

Let the origin be (x1, y1) and let (7, 16) be (x2, y2). Then, we have:



This is equivalent to:


Since 305=5×61, this number is in simplest form.

Line B:

Let the origin be (x1, y1), and let (-7, 16) be (x2, y2). Then, we have:



As before, then, D=√(305).

Line C:

Once again, let (x1, y1) be the origin and (-7, -16) be (x2, y2). The distance is:



Again, the distance is D=√(305).

Line D:

Finally, let (x1, y1) be the origin and let (7, -16) be (x2, y2). The distance is:



Like the other lines, D’s distance is D=√(305).

This example Illustrates both the fact that the distances do not have to be whole numbers and that, since the horizontal and vertical differences are squared in the formula, the order of the numbers is not very important.

Example 3

Find the distance between the points (-8, 3) and (5, 6).

Example 3 Solution

Let’s let (-8, 3) be the point (x1, y1), and let (5, 6) be (x2, y2).

Then, plugging the values into the formula gives us:



Simplifying further gives us



Since 178=2×89, √(178) cannot be further simplified. Therefore, this is the distance between the two points.

Example 4

Find perimeter of the triangle with end points ABC, where A=(1, 2), B=(-3, 4), and C=(-1, -5).

Example 4 Solution

We have to first find the lengths of AB, BC, and AC, and then add them up.


Let A be (x1, y1), and let B be (x2, y2). AB is:



This further simplifies to:



Since 20 is divisible by 4, √(20)=√(4×5)=√(4)×√(5)=2√(5).


Let B be (x1, y1) and let C be (x2, y2). The distance is:



This is:



Since 85=17×5, √(85) cannot be simplified and is the length of the segment.


Let A be (x1, y1), and C be (x2, y2). The length of the line segment is:



This simplifies to:



Since 53 is prime, this length is √(53).

Therefore, the perimeter is√(53)+√(5)+2√(5). It’s okay to leave this number as is. Rounding to the nearest hundredth, however, gives us 20.97.

Example 5

The lines A and B have the same distance. If A has coordinates at (8, 2) and (-3, -4) and B has coordinates at (6, 4) and (7, c), what is the value of c?

Example 5 Solution

In this case, we will have to find the length of A and then work backwards to find the value of c.

Let (8, 2) be (x1, y1), and let (-3, -4) be (x2, y2).

Then, the length of A is:



Simplifying further gives us



Since 157 is prime, this is the length of A.

Now, since we already know the length of B and three of the four coordinates, we can plug in the values we know. Let (6, 4) be (x1, y1), and let (7, c) be (x2, y2).



Squaring both sides gives us:



Now, we take the square root of both sides to get:


Therefore, 4-√(156)=c. Since 156 is divisible by 4, this can be further simplified to c=4(1-√(39)).

Example 6

A farmer looks at a survey of his property. He wants to build a new fence that extends from a point one-half acre east and one-fourth of an acre north of the southwest corner of his property to a point two acres east and one and a half acres north of the southwest corner of his property. What is the length of the fence?

Example 6 Solution

First, we need t convert the fence’s endpoints to coordinates. Let’s let the southwest corner of the property be the reference point and east and north be the positive direction. Therefore, the starting point for the fence is (½, ¼). Let’s call this (x1, y1). The ending point, (x2, y2) is (2, 3/2).

The length of the fence is therefore:



Squaring the numerator and denominator of the improper fractions gives us:


This is:


We can rewrite this as 1/4√(61) acres.

Practice Questions

1. What is the perimeter of the figure shown?

Quadrilateral for PP1

2. What is the length of a line segment that extends from $(-12, 15)$ to $(-3, 21)$?

3. What is the perimeter of a triangle with vertices at $(-1, 31)$, $(-6, 19)$, and $(5, 26)$?

4. Line A has endpoints at $(-1, 1)$ and $(3, 5)$. Line B has endpoints at $(5, 6)$ and $(c, 9)$. If the two lines have the same length, what is the value of $c$?

5. An archaeologist plots the location of artifacts in the ruins of a house. A piece of pottery is found two meters to the left of the front door and one meter inside. A coin is found two meters inside and one half a meter to the right. How far apart are the two artifacts?


Previous Lesson | Main Page | Next Lesson