Skip to content

Distance Formula in Coordinate Geometry

11 formulasCalculatorUpdated 22 Oct 2026

The distance formula gives the length of the straight segment joining two points A(x1,y1)A(x_1, y_1) and B(x2,y2)B(x_2, y_2): d=(x2−x1)2+(y2−y1)2d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}. Subtract the x values, subtract the y values, square both differences, add, and take the square root. That is all it does, and it works for any two points in the plane.

This page covers the distance formula in maths from its Pythagoras proof to the version with three coordinates, then the other formulas that travel with it in class 10 and class 11: the midpoint formula, the section formula (internal and external), the slope formula and the two point form of a line, the collinearity test and the triangle area you get straight from three vertices. Each one comes with a short example worked step by step, and the calculator below lets you check your own answers.

Distance formula

Key formulas

  • Distance formula (two points)

    d=(x2−x1)2+(y2−y1)2d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}

    Also called the Euclidean distance formula

  • Distance from the origin

    OP=x2+y2OP = \sqrt{x^2 + y^2}
  • Distance formula with three coordinates

    d=(x2−x1)2+(y2−y1)2+(z2−z1)2d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}
  • Midpoint formula

    M=(x1+x22, y1+y22)M = \left(\dfrac{x_1 + x_2}{2},\ \dfrac{y_1 + y_2}{2}\right)
  • Section formula (internal, ratio m:n)

    P=(mx2+nx1m+n, my2+ny1m+n)P = \left(\dfrac{m x_2 + n x_1}{m + n},\ \dfrac{m y_2 + n y_1}{m + n}\right)
  • Section formula (external, ratio m:n)

    P=(mx2−nx1m−n, my2−ny1m−n)P = \left(\dfrac{m x_2 - n x_1}{m - n},\ \dfrac{m y_2 - n y_1}{m - n}\right)
  • Slope formula

    m=y2−y1x2−x1=tan⁡θm = \dfrac{y_2 - y_1}{x_2 - x_1} = \tan\theta
  • Two point slope form of a line

    y−y1=y2−y1x2−x1 (x−x1)y - y_1 = \dfrac{y_2 - y_1}{x_2 - x_1}\,(x - x_1)
  • Area of a triangle from coordinates

    Δ=12∣x1(y2−y3)+x2(y3−y1)+x3(y1−y2)∣\Delta = \tfrac{1}{2}\left|x_1(y_2 - y_3) + x_2(y_3 - y_1) + x_3(y_1 - y_2)\right|
  • Centroid of a triangle

    G=(x1+x2+x33, y1+y2+y33)G = \left(\dfrac{x_1 + x_2 + x_3}{3},\ \dfrac{y_1 + y_2 + y_3}{3}\right)
  • Point to line distance formula

    p=∣ax0+by0+c∣a2+b2p = \dfrac{|a x_0 + b y_0 + c|}{\sqrt{a^2 + b^2}}

    distance of (x0,y0)(x_0, y_0) from the line ax+by+c=0ax + by + c = 0

The distance formula, term by term

Take two points A(x1,y1)A(x_1, y_1) and B(x2,y2)B(x_2, y_2). The formula is

AB=(x2−x1)2+(y2−y1)2 AB = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}
  • x2−x1x_2 - x_1 is the horizontal gap between the points (how far you move left or right).
  • y2−y1y_2 - y_1 is the vertical gap (how far you move up or down).
  • Squaring removes the sign, so it does not matter which point you call A and which you call B.
  • The square root turns the sum of squares back into a length, in the same units as the axes.

The answer is never negative. If you get zero, the two points are the same point. Because the straight segment is the shortest path between two points in a plane, this point to point distance formula always gives the shortest distance, and teachers often add that the shortest distance between two points is a straight line. Many books call it the Euclidean distance formula, after Euclid, and the same idea with more terms under the root is used for vectors and in data science.

Proof of the distance formula from Pythagoras (class 10)

Plot A(x1,y1)A(x_1, y_1) and B(x2,y2)B(x_2, y_2). Draw a horizontal line through A and a vertical line through B. They meet at C(x2,y1)C(x_2, y_1), and angle C is a right angle.

  • Side AC lies along a horizontal line, so its length is ∣x2−x1∣|x_2 - x_1|.
  • Side BC lies along a vertical line, so its length is ∣y2−y1∣|y_2 - y_1|.

By the Pythagoras theorem in right triangle ACB:

AB2=AC2+BC2=(x2−x1)2+(y2−y1)2AB=(x2−x1)2+(y2−y1)2 \begin{aligned} AB^2 &= AC^2 + BC^2 \\ &= (x_2 - x_1)^2 + (y_2 - y_1)^2 \\ AB &= \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2} \end{aligned}

This is the derivation of the distance formula used in the class 10 coordinate geometry chapter, and you may be asked to write it out. To verify the distance formula by a graphical method, plot two points on graph paper, measure the segment with a scale, and compare it with the value from the formula. They agree up to your measuring error.

Distance in 3D and from the origin

When one of the points is the origin O(0,0)O(0, 0), put x1=y1=0x_1 = y_1 = 0 and the formula shrinks to OP=x2+y2OP = \sqrt{x^2 + y^2}. For P(7,−24)P(7, -24), OP=49+576=625=25OP = \sqrt{49 + 576} = \sqrt{625} = 25.

In space each point has three coordinates. Class 11 adds a third squared gap:

d=(x2−x1)2+(y2−y1)2+(z2−z1)2 d = \sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2}

For P(1,2,3)P(1, 2, 3) and Q(4,6,15)Q(4, 6, 15), the gaps are 3, 4 and 12, so PQ=9+16+144=169=13PQ = \sqrt{9 + 16 + 144} = \sqrt{169} = 13. The same pattern works with vectors: the distance between position vectors a⃗\vec a and b⃗\vec b is the magnitude ∣b⃗−a⃗∣|\vec b - \vec a|, which is why the vector distance formula looks identical once you write the components out. In calculus the distance formula applied to tiny pieces of a curve leads to the arc length integral you meet on the integration formulas page.

Midpoint formula

The midpoint of AB is the point exactly halfway along it. Its x value is the average of the two x values and its y value is the average of the two y values:

M=(x1+x22, y1+y22) M = \left(\dfrac{x_1 + x_2}{2},\ \dfrac{y_1 + y_2}{2}\right)

For A(2,3)A(2, 3) and B(8,11)B(8, 11), M=(102,142)=(5,7)M = \left(\tfrac{10}{2}, \tfrac{14}{2}\right) = (5, 7). Notice the plus signs: the midpoint adds coordinates, the distance formula subtracts them. Students mix these up under pressure. The mid point formula in class 10 is simply the section formula with the ratio 1:1, so you do not need to learn it as a separate idea. A related result is the centroid of a triangle, found by averaging all three vertices.

Section formula for class 10

The section formula finds the point P that divides the segment from A(x1,y1)A(x_1, y_1) to B(x2,y2)B(x_2, y_2) in the ratio m:nm:n, meaning AP:PB=m:nAP : PB = m : n.

Internal division

P lies between A and B:

P=(mx2+nx1m+n, my2+ny1m+n) P = \left(\dfrac{m x_2 + n x_1}{m + n},\ \dfrac{m y_2 + n y_1}{m + n}\right)

Memory hook: m goes with the far point B, n goes with the near point A. Cross multiplication, not straight.

External division

P lies on line AB extended beyond B (when m is larger than n). Change both plus signs between the products to minus:

P=(mx2−nx1m−n, my2−ny1m−n) P = \left(\dfrac{m x_2 - n x_1}{m - n},\ \dfrac{m y_2 - n y_1}{m - n}\right)

External division is not in the class 10 NCERT book; it turns up mainly in competitive exams. The class 10 NCERT chapter on coordinate geometry uses only the internal form, often in questions like "in what ratio does the x axis divide the segment".

Slope formula and the two point form of a line

The slope (gradient) of the line through two points measures how steep it is: rise divided by run.

m=y2−y1x2−x1=tan⁡θ m = \dfrac{y_2 - y_1}{x_2 - x_1} = \tan\theta

Here θ\theta is the angle the line makes with the positive x axis, which links slope to the trigonometry formulas. A positive slope rises to the right, a negative slope falls, a horizontal line has slope 0, and a vertical line has no defined slope because x2−x1=0x_2 - x_1 = 0.

Put the slope into the point slope form and you get the two point slope formula (some books write 2 point slope formula) for the line itself:

y−y1=y2−y1x2−x1 (x−x1) y - y_1 = \dfrac{y_2 - y_1}{x_2 - x_1}\,(x - x_1)

Other slope results you should know: slope from the equation y=mx+cy = mx + c is m; slope from ax+by+c=0ax + by + c = 0 is −ab-\tfrac{a}{b} (when b is not 0); parallel lines have equal slopes; perpendicular lines have slopes whose product is −1-1. Students of statistics also meet a slope formula in linear regression, but that one is built from sums of data values rather than two points.

Collinear points and area of a triangle

Three points are collinear when they lie on one straight line. There are three ways to test this, and all of them come from the formulas above:

  1. Slopes: slope of AB equals slope of BC.
  2. Distances: the two shorter distances add up to the longest one.
  3. Area: the triangle formed has zero area.

Given vertices (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2), (x3,y3)(x_3, y_3), the enclosed area is

Δ=12∣x1(y2−y3)+x2(y3−y1)+x3(y1−y2)∣ \Delta = \tfrac{1}{2}\left|x_1(y_2 - y_3) + x_2(y_3 - y_1) + x_3(y_1 - y_2)\right|

For the vertices (1,1)(1, 1), (5,2)(5, 2) and (3,6)(3, 6): 12∣1(2−6)+5(6−1)+3(1−2)∣=12∣−4+25−3∣=9\tfrac{1}{2}|1(2 - 6) + 5(6 - 1) + 3(1 - 2)| = \tfrac{1}{2}|{-4} + 25 - 3| = 9 square units. If you only know the three side lengths, use Heron's formula instead, and the area formulas page lists the base and height methods.

Distance formula examples, solved step by step

Example 1: find the distance between two points

Find the distance between A(2,3)A(2, 3) and B(8,11)B(8, 11).

x2−x1=8−2=6x_2 - x_1 = 8 - 2 = 6 and y2−y1=11−3=8y_2 - y_1 = 11 - 3 = 8.

AB=62+82=36+64=100AB = \sqrt{6^2 + 8^2} = \sqrt{36 + 64} = \sqrt{100}.

Answer: AB=10AB = 10 units.

Example 2: negative coordinates and a surd answer

Find the distance between P(−3,5)P(-3, 5) and Q(4,−2)Q(4, -2).

x2−x1=4−(−3)=7x_2 - x_1 = 4 - (-3) = 7 and y2−y1=−2−5=−7y_2 - y_1 = -2 - 5 = -7.

PQ=49+49=98=72PQ = \sqrt{49 + 49} = \sqrt{98} = 7\sqrt{2}.

Answer: 72≈9.907\sqrt{2} \approx 9.90 units. Leave it in surd form unless the question asks for a decimal.

Example 3: an unknown coordinate

The distance between (2,y)(2, y) and (10,−9)(10, -9) is 10 units. Find y.

(10−2)2+(−9−y)2=100(10 - 2)^2 + (-9 - y)^2 = 100, so 64+(y+9)2=10064 + (y + 9)^2 = 100.

(y+9)2=36(y + 9)^2 = 36, so y+9=6y + 9 = 6 or y+9=−6y + 9 = -6.

Answer: y=−3y = -3 or y=−15y = -15. Both are valid: there are two points at that distance.

Example 4: ratio of division by the x axis

In what ratio does the x axis divide the segment joining A(−4,6)A(-4, 6) and B(8,−3)B(8, -3)? Find the point.

Let the ratio be k:1k : 1. Any point on the x axis has y equal to 0, so k(−3)+1(6)k+1=0\dfrac{k(-3) + 1(6)}{k + 1} = 0, giving k=2k = 2.

x coordinate: 2(8)+1(−4)2+1=123=4\dfrac{2(8) + 1(-4)}{2 + 1} = \dfrac{12}{3} = 4.

Answer: the ratio is 2:1 and the point is (4,0)(4, 0).

Example 5: slope, line and collinearity

Show that (−1,−4)(-1, -4), (2,2)(2, 2) and (4,6)(4, 6) are collinear.

Slope of the first pair: 2−(−4)2−(−1)=63=2\dfrac{2 - (-4)}{2 - (-1)} = \dfrac{6}{3} = 2. Slope of the second pair: 6−24−2=2\dfrac{6 - 2}{4 - 2} = 2.

Equal slopes with a common point mean one line. Check with area: 12∣−1(2−6)+2(6+4)+4(−4−2)∣=12∣4+20−24∣=0\tfrac{1}{2}|-1(2 - 6) + 2(6 + 4) + 4(-4 - 2)| = \tfrac{1}{2}|4 + 20 - 24| = 0.

Answer: the points are collinear, on the line y=2x−2y = 2x - 2.

Common mistakes with these formulas

Watch out for these:

  • Writing (x2−x1)+(y2−y1)\sqrt{(x_2 - x_1) + (y_2 - y_1)} and forgetting to square the gaps.
  • Taking the square root of each term separately. 36+64\sqrt{36 + 64} is 10, not 6 + 8.
  • Losing a minus sign: 4−(−3)4 - (-3) is 7, not 1. Put brackets around negative coordinates every time.
  • Using minus signs in the midpoint formula or plus signs in the distance formula.
  • Swapping m and n in the section formula. Check that your point really is closer to the end with the smaller share.
  • Dividing in the wrong order in the slope formula, such as y2−y1x1−x2\tfrac{y_2 - y_1}{x_1 - x_2}, which flips the sign.

Where these formulas appear in exams

Class 10 maths coordinate geometry formulas in the NCERT book are the distance formula and the section formula (with the midpoint as a special case). Expect a 2 or 3 mark question on finding a distance or a ratio, and one word problem where points stand for houses, trees or towns on a map and you have to show they form an isosceles or right triangle. Class 11 adds slope, the forms of a straight line, the point to line distance formula and the 3D distance formula. Engineering and other entrance tests mix all of these with circles, where the radius formula in coordinate geometry is the distance formula used once, between the centre and a known point of the circle.

The formula sheet PDF below gives you a one page revision copy. For every other chapter, see the full list on the all maths formulas page.

Practice: (1) Distance between (−3,−5)(-3, -5) and (5,1)(5, 1). (2) Midpoint of (−6,4)(-6, 4) and (2,−8)(2, -8). (3) Point dividing (1,−2)(1, -2) to (10,7)(10, 7) internally in 2:1. (4) Point dividing (2,1)(2, 1) to (5,4)(5, 4) externally in 2:1. Answers: (1) 10, (2) (−2,−2)(-2, -2), (3) (7,4)(7, 4), (4) (8,7)(8, 7).

Download the PDF

Questions students ask

What is the distance formula in coordinate geometry?

For points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2), the distance is (x2−x1)2+(y2−y1)2\sqrt{(x_2 - x_1)^2 + (y_2 - y_1)^2}. It is the Pythagoras theorem applied to the horizontal and vertical gaps between the points.

In which class is the distance formula taught?

Class 10 students meet it in the coordinate geometry chapter along with the section formula. Class 11 extends it to three dimensions and adds slope and straight lines.

What is the difference between the distance formula and the midpoint formula?

The distance formula gives a length (one number) by subtracting coordinates, squaring and taking a root. The midpoint formula gives a point (two coordinates) by averaging the x values and the y values.

Does it matter which point I take first?

No. Each gap is squared, and (x1−x2)2=(x2−x1)2(x_1 - x_2)^2 = (x_2 - x_1)^2. Just keep the order the same for x and y in the slope formula, where the sign matters.

How do I find the distance between a point and a line?

Write the line as ax+by+c=0ax + by + c = 0. The perpendicular distance of (x0,y0)(x_0, y_0) from it is ∣ax0+by0+c∣a2+b2\dfrac{|ax_0 + by_0 + c|}{\sqrt{a^2 + b^2}}. For (3,4)(3, 4) and 3x+4y−5=03x + 4y - 5 = 0 this is ∣9+16−5∣5=4\dfrac{|9 + 16 - 5|}{5} = 4.

Why is the shortest distance between two points a straight line?

In a flat plane, any bent path can be shortened by joining its ends directly, which is the triangle inequality: one side of a triangle is shorter than the other two put together. In physics, this straight line length from start to end is the magnitude of the displacement.