If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

Distance formula

Walk through deriving a general formula for the distance between two points.
The start color #11accd, start text, d, i, s, t, a, n, c, e, end text, end color #11accd between the points left parenthesis, start color #1fab54, x, start subscript, 1, end subscript, end color #1fab54, comma, start color #e07d10, y, start subscript, 1, end subscript, end color #e07d10, right parenthesis and left parenthesis, start color #1fab54, x, start subscript, 2, end subscript, end color #1fab54, comma, start color #e07d10, y, start subscript, 2, end subscript, end color #e07d10, right parenthesis is given by the following formula:
square root of, left parenthesis, start color #1fab54, x, start subscript, 2, end subscript, minus, x, start subscript, 1, end subscript, end color #1fab54, right parenthesis, squared, plus, start color #e07d10, left parenthesis, y, start subscript, 2, end subscript, minus, y, start subscript, 1, end subscript, end color #e07d10, right parenthesis, squared, end square root
In this article, we're going to derive this formula!

Deriving the distance formula

Let's start by plotting the points left parenthesis, start color #1fab54, x, start subscript, 1, end subscript, end color #1fab54, comma, start color #e07d10, y, start subscript, 1, end subscript, end color #e07d10, right parenthesis and left parenthesis, start color #1fab54, x, start subscript, 2, end subscript, end color #1fab54, comma, start color #e07d10, y, start subscript, 2, end subscript, end color #e07d10, right parenthesis.
The first quadrant of a coordinate plane with two tick marks on the x axis labeled x one and x two. There are two tick marks on the y axis labeled y one and y two. There is a point at x one, y one and another point at x two, y two.
The length of the segment between the two points is the start color #11accd, start text, d, i, s, t, a, n, c, e, end text, end color #11accd between them:
The first quadrant of a coordinate plane with two tick marks on the x axis labeled x one and x two. There are two tick marks on the y axis labeled y one and y two. There is a point at x one, y one and another point at x two, y two. A line connects the two points.
We want to find the start color #11accd, start text, d, i, s, t, a, n, c, e, end text, end color #11accd. If we draw a right triangle, we'll be able to use the Pythagorean theorem!
The first quadrant of a coordinate plane with two tick marks on the x axis labeled x one and x two. There are two tick marks on the y axis labeled y one and y two. There is a point at x one, y one and another point at x two, y two. A line connects the two points. A third unlabeled point is at x two, y one with a line connecting from it to the point at x two, y two and another line connecting from it to the point at x one, y one forming a right triangle.
An expression for the length of the base is start color #1fab54, x, start subscript, 2, end subscript, minus, x, start subscript, 1, end subscript, end color #1fab54:
The first quadrant of a coordinate plane with two tick marks on the x axis labeled x one and x two. There are two tick marks on the y axis labeled y one and y two. There is a point at x one, y one and another point at x two, y two. A line connects the two points. A third unlabeled point is at x two, y one with a line connecting from it to the point at x two, y two and another line connecting from it to the point at x one, y one forming a right triangle. The hypotenuse of the right triangle is unknown and the side made from the point at x one, y one and x two, y one is labeled x two minus x one.
Similarly, an expression for the length of the height is start color #e07d10, y, start subscript, 2, end subscript, minus, y, start subscript, 1, end subscript, end color #e07d10:
The first quadrant of a coordinate plane with two tick marks on the x axis labeled x one and x two. There are two tick marks on the y axis labeled y one and y two. There is a point at x one, y one and another point at x two, y two. A line connects the two points. A third unlabeled point is at x two, y one with a line connecting from it to the point at x two, y two and another line connecting from it to the point at x one, y one forming a right triangle. The hypotenuse of the right triangle is unknown and the side made from the point at x one, y one and x two, y one is labeled x two minus x one. The third side is labeled y two minus y one.
Now we can use the Pythagorean theorem to write an equation:
start color #11accd, question mark, end color #11accd, squared, equals, left parenthesis, start color #1fab54, x, start subscript, 2, end subscript, minus, x, start subscript, 1, end subscript, end color #1fab54, right parenthesis, squared, plus, start color #e07d10, left parenthesis, y, start subscript, 2, end subscript, minus, y, start subscript, 1, end subscript, end color #e07d10, right parenthesis, squared
We can solve for start color #11accd, question mark, end color #11accd by taking the square root of each side:
start color #11accd, question mark, end color #11accd, equals, square root of, left parenthesis, start color #1fab54, x, start subscript, 2, end subscript, minus, x, start subscript, 1, end subscript, end color #1fab54, right parenthesis, squared, plus, start color #e07d10, left parenthesis, y, start subscript, 2, end subscript, minus, y, start subscript, 1, end subscript, end color #e07d10, right parenthesis, squared, end square root
That's it! We derived the distance formula!
Interestingly, a lot of people don't actually memorize this formula. Instead, they set up a right triangle, and use the Pythagorean theorem whenever they want to find the distance between two points.

Want to join the conversation?

  • aqualine tree style avatar for user rose
    who came up with this formula?
    (33 votes)
    Default Khan Academy avatar avatar for user
  • male robot hal style avatar for user EvanCole06
    For those having trouble, it helped me to imagine a scenario that this could be used in. WAR!

    Imagine this, you are the admiral of a ship in WW2. You have sighting reports and coordinates of an enemy fleet. You have been tasked to intercept this force and destroy it. One thing that must be done before any action is made is finding the distance between you and the enemy. This can be represented by the "Distance" (Hypotenuse). In order to calculate that distance you must use a coordinate graph to find that distance. You must use the change in X and the change in Y on the coordinate plane.

    First, find out how many spaces over he is to the Left/Right of you (X Value) then you must see how many spaces Up/Down he is from you (Y value)

    You can then use the distance formula which is just a variant of the Pythagorean theorem to calculate the distance. It starts out as D^2 = (x2 - x1)^2 this is basically taking the distance between the X value of where you are and the X value of where your enemy is. You square it because that is required for the theorem to work. Then you do the same for the Y value. (y2 - y1)^2. Now that you have found Delta X and Delta Y (Change in X and change in Y) You can put it into the formula and launch your attack. The formula is now

    D^2 = DeltaX^2 + DeltaY ^2

    Then make sure you find out the Square root to get it to a normal number again and there you go!

    You now know the distance and the location of your enemy. You can now launch your attack!

    (Hope this wasn't too confusing, I tried to put it in a more practical light)
    (53 votes)
    Default Khan Academy avatar avatar for user
  • male robot johnny style avatar for user Ivan Brown
    I still don't understand any of this... :I
    (10 votes)
    Default Khan Academy avatar avatar for user
    • aqualine seedling style avatar for user Ethan
      I haven't read any of the article on this so I really hope I don't say the exact same thing he says.... here goes:

      Here is the graph I am referring to in my explanation: https://www.desmos.com/calculator/juthaysfbl
      -- only look at the graph, ignore everything on the sides and bottom --

      (intuitive solution, and how I learned this)

      Think of the Pythagorean theorem. The formula is a^2 + b^2 = c^2 . Now, imagine two points, let's say they are (0,0) and (3,4) to keep it simple. Look at the blue line going from (0,0) to (3,0). This is the base, with a distance of 3 units. How did we find this? We took one of the x values (3) and subtracted it by the other (0). 3 - 0 = 0. Next, we must find the height. The red line represents it, and it is a length of 4 units. We found this, again, by subtracting the y values (4 - 0 = 0). We can now find the hypotenuse, if we replace a and b with the base height length, so we get 3^2 + 4^2 = c^2 (where c is the orange line, or hypotenuse). The hypotenuse is the distance of the two points.

      Of course, we can square root both sides so we get c = sqrt( 3^2 + 4^2). We can expand this even further if we replace the 3 and 4 with how we got there, so c = sqrt( (3 - 0)^2 + (4 - 0)^2). But what do 3 and 0 and 4 and 0 mean? The two x values and y values, respectively. Therefore, we replace the numbers so we get c (hypotenuse) = ( ( x1 - x2) ^2 + (y1 - y2) ^2) .

      I really hope this helped you, I spent a long time explaining this lmao...
      (57 votes)
  • blobby green style avatar for user bpjblr
    POV: your teacher makes you show your work
    (21 votes)
    Default Khan Academy avatar avatar for user
  • mr pink red style avatar for user jasontheking121
    how is the formula the same as the Pythagorean theorem
    (10 votes)
    Default Khan Academy avatar avatar for user
  • spunky sam blue style avatar for user malexander8
    okay I understand all you have to do is take your y axis and divide it by your x axis
    (11 votes)
    Default Khan Academy avatar avatar for user
    • duskpin seed style avatar for user Marisah visaiz
      If you were to get two perfect squares under the giant square root after subtracting the two points within each parentheses, would you be able to separate them in order to pull them out of the square root and make them rational?
      For example, if I got "the square root of (6)^squared + (6)^squared" would I first square them and get "the square root of 36+36?" or could I separate them into "the square root of 36 + the square root of 36"
      (19 votes)
  • marcimus purple style avatar for user ur mom
    bro why do we have to do this
    (14 votes)
    Default Khan Academy avatar avatar for user
    • duskpin ultimate style avatar for user Jackandmoo
      I cannot say why you have to, but I can say why this might be useful in the future.
      Lets say for whatever reason you needed to make a video game, and let’s also say you needed to calculate the distance between a player and an object in order to make an action occur. I imagine this would be useful for those purposes
      (13 votes)
  • spunky sam blue style avatar for user Pink_Ivy_Nikes
    Sooooo, if I have two points, (1, 2) and (-1, 4), it does not matter in which order I subtract as long as I do the x with the x, and so on? Because it doesn't look that way.
    (4 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user Maria Lopes
    what is the formula that is used to find distance between two points
    (0 votes)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user Eleanor Brown
    I don't get it and I have a test tomorrow it's hard for sixth grade
    (8 votes)
    Default Khan Academy avatar avatar for user