Lines & Graphs

Equation of a Line Through Two Points

To find the equation of a line from two points, calculate the slope m=y2−y1x2−x1m = \frac{y_2 - y_1}{x_2 - x_1}, then substitute either point into y−y1=m(x−x1)y - y_1 = m(x - x_1) and simplify.

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

Try it with your numbers

Show every step

The whole method is two small moves: one subtraction-and-division, one substitution. Almost every lost mark comes from sign slips in the first move or from the special cases covered below, so those are worth a closer look than the routine steps.

How do you find the equation of a line from two points?

Start with the slope formula, because the slope is the only thing the line needs beyond a single anchor point. Then use that anchor point in point-slope form, and tidy the result into slope-intercept form if the problem asks for y=mx+by = mx + b.

  1. Label the points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2).
  2. Compute m=y2−y1x2−x1m = \frac{y_2 - y_1}{x_2 - x_1}.
  3. Substitute mm and one point into y−y1=m(x−x1)y - y_1 = m(x - x_1).
  4. Distribute, then solve for yy.

Example 1. Find the line through (1,3)(1, 3) and (4,9)(4, 9).

m=9−34−1=63=2m = \frac{9 - 3}{4 - 1} = \frac{6}{3} = 2

y−3=2(x−1)y - 3 = 2(x - 1)

y=2x−2+3=2x+1y = 2x - 2 + 3 = 2x + 1

Check the point you did not use: at x=4x = 4, y=2(4)+1=9y = 2(4) + 1 = 9. It matches, so the equation is y=2x+1y = 2x + 1.

One shortcut is worth keeping. Once you know mm, the intercept is b=y1−mx1b = y_1 - m x_1, which saves the distribute-and-collect step. For Example 1 that gives b=3−2(1)=1b = 3 - 2(1) = 1, in a single line.

Where does the two-point formula come from?

Take any point (x,y)(x, y) on the line. The slope from (x1,y1)(x_1, y_1) to (x,y)(x, y) must equal the slope between the two given points, because a straight line has only one slope. Writing that as an equation gives the two-point form:

y−y1x−x1=y2−y1x2−x1\frac{y - y_1}{x - x_1} = \frac{y_2 - y_1}{x_2 - x_1}

Multiply both sides by x−x1x - x_1 and you get y−y1=m(x−x1)y - y_1 = m(x - x_1), the point-slope form. Nothing more is hiding in there: the formula is a statement that every point on the line shares one slope.

Cross-multiplying gives a version without division: (y−y1)(x2−x1)=(y2−y1)(x−x1)(y - y_1)(x_2 - x_1) = (y_2 - y_1)(x - x_1). This form never breaks, even when x2=x1x_2 = x_1. It also has a compact matrix form, since three points are collinear exactly when a 3×3 determinant vanishes:

∣xy1x1y11x2y21∣=0\begin{vmatrix} x & y & 1 \\ x_1 & y_1 & 1 \\ x_2 & y_2 & 1 \end{vmatrix} = 0

For Example 1, expanding gives −6x+3y−3=0-6x + 3y - 3 = 0. Divide by 3 and solve for yy, and the result is y=2x+1y = 2x + 1, the same line.

Quick check

The point (x,7)(x, 7) lies on the line through (1,3)(1, 3) and (3,5)(3, 5). Find xx.

Equation of a line through two points with negative numbers

Same-order versus mixed-order subtraction giving slope negative one versus positive one for two points
Both subtractions must start from the same point, or the slope sign flips.

Negatives do not change the method, only the bookkeeping. Wrap every negative coordinate in parentheses before subtracting, and subtract in the same order on top and bottom.

Example 2. Find the line through (−2,5)(-2, 5) and (4,−1)(4, -1).

m=−1−54−(−2)=−66=−1m = \frac{-1 - 5}{4 - (-2)} = \frac{-6}{6} = -1

y−5=−1(x−(−2))=−(x+2)y - 5 = -1\bigl(x - (-2)\bigr) = -(x + 2)

y=−x−2+5=−x+3y = -x - 2 + 5 = -x + 3

Check (4,−1)(4, -1): −4+3=−1-4 + 3 = -1. Correct.

You can also sanity-check the sign of the slope before doing any algebra. Moving from left to right, the y-values drop from 55 to −1-1, so the line falls and mm must be negative. A positive slope here means a sign slip somewhere.

The order trap

Both subtractions must start from the same point. −1−54−(−2)\frac{-1-5}{4-(-2)} and 5−(−1)−2−4\frac{5-(-1)}{-2-4} both give −1-1, but −1−5−2−4\frac{-1-5}{-2-4} gives +1+1, the wrong sign.

How do you handle fractions and write standard form?

When the slope is a fraction, clear the denominator before you distribute. It keeps the arithmetic in whole numbers, and it is also exactly what standard form Ax+By=CAx + By = C wants.

Example 3. Find the line through (1,−2)(1, -2) and (5,1)(5, 1), in slope-intercept and standard form.

m=1−(−2)5−1=34m = \frac{1 - (-2)}{5 - 1} = \frac{3}{4}

y+2=34(x−1)y + 2 = \frac{3}{4}(x - 1)

For slope-intercept form, distribute and subtract 2:

y=34x−34−2=34x−114y = \frac{3}{4}x - \frac{3}{4} - 2 = \frac{3}{4}x - \frac{11}{4}

For standard form, multiply the point-slope equation by 4 first:

4y+8=3x−3⟹3x−4y=114y + 8 = 3x - 3 \quad\Longrightarrow\quad 3x - 4y = 11

Check both points in the standard form: 3(1)−4(−2)=3+8=113(1) - 4(-2) = 3 + 8 = 11 and 3(5)−4(1)=15−4=113(5) - 4(1) = 15 - 4 = 11. Both work.

The usual convention is integer coefficients with AA positive, so if your first attempt gives −3x+4y=−11-3x + 4y = -11, multiply through by −1-1. Both describe the same line, but many answer keys expect the positive-AA version.

What if the two points are vertical or horizontal?

Horizontal line y = 7 and vertical line x = 4 compared with their slope calculations
A zero numerator gives slope 0, while a zero denominator signals a vertical line.

If the two points share an x-coordinate, the slope formula divides by zero. That is not a calculation error: a vertical line has no slope, and no y=mx+by = mx + b equation exists for it. The line is simply x=cx = c.

Example 4. Find the line through (4,2)(4, 2) and (4,−5)(4, -5). Both x-values are 44, so the denominator is 4−4=04 - 4 = 0 and the line is x=4x = 4. The cross-multiplied form agrees: (y−2)(4−4)=(−5−2)(x−4)(y - 2)(4 - 4) = (-5 - 2)(x - 4) reduces to 0=−7(x−4)0 = -7(x - 4), which gives x=4x = 4.

The opposite case is gentler. Points (−3,7)(-3, 7) and (5,7)(5, 7) give m=7−75−(−3)=0m = \frac{7 - 7}{5 - (-3)} = 0, so y−7=0y - 7 = 0 and the line is y=7y = 7. A zero numerator is fine; only a zero denominator breaks the formula. See horizontal and vertical lines for how these two cases look on a graph.

A two-second test before any calculation: same x means vertical, same y means horizontal. Check for it first and you will never feed a zero denominator into a calculator.

Quick check

Write the equation of the line through (−3,4)(-3, 4) and (−3,−9)(-3, -9).

How do you check the equation of a line?

The strongest check uses a point the algebra did not rely on. If you built the equation with (x1,y1)(x_1, y_1), substitute (x2,y2)(x_2, y_2). A wrong slope or intercept almost always fails this test, since an error would have to fit both points to survive.

A few more fast checks catch different mistakes:

  • The slope sign matches the picture: rising left to right means positive, falling means negative.
  • If one point has x=0x = 0, its y-value must equal bb.
  • Both points satisfy the final equation, not just one.

When the answer still feels off, plot the points and draw the line. If it misses either point, the equation is wrong, and the position of the miss tells you whether the slope or the intercept is at fault.

Try this: Find the line through (2,1)(2, 1) and (6,9)(6, 9) twice, once using (2,1)(2, 1) as (x1,y1)(x_1, y_1) and once using (6,9)(6, 9). Simplify both to y=mx+by = mx + b and confirm they match.

Two-point form vs point-slope form and the distance formula

The two-point form is point-slope form with the slope already substituted in. Point-slope needs a point and a slope; two-point form needs only two points. They are the same idea at different stages.

Students also mix up the formulas that take two points as input, because several of them do:

Formula Input Output
Slope formula two points steepness mm
Two-point form two points the full line equation
Distance formula two points length between them
Midpoint formula two points the point halfway between

The slope formula is the first half of the line-finding method, never a replacement for it. Reading a problem for what it asks (an equation, a length or a point) picks the right formula in one glance.

Slope is not distance

For (1,3)(1, 3) and (4,9)(4, 9) the slope is 22, but the distance is 32+62=45=35\sqrt{3^2 + 6^2} = \sqrt{45} = 3\sqrt{5}. Slope measures tilt, distance measures length.

Where is the equation of a line from two points used?

Whenever two measurements are assumed to be linked at a steady rate, two data points define the model. The slope is the average rate of change, and the intercept is the starting value.

Example 5. A taxi charges 7 dollars for a 2 mile ride and 15 dollars for a 6 mile ride. Treat (2,7)(2, 7) and (6,15)(6, 15) as points (miles,cost)(\text{miles}, \text{cost}).

m=15−76−2=2,7=2(2)+b  ⇒  b=3m = \frac{15 - 7}{6 - 2} = 2, \qquad 7 = 2(2) + b \;\Rightarrow\; b = 3

The model is C=2x+3C = 2x + 3: a 3 dollar base fee plus 2 dollars per mile. A 10 mile ride predicts 2(10)+3=232(10) + 3 = 23 dollars.

The same method converts temperatures. Water freezes at (0,32)(0, 32) and boils at (100,212)(100, 212) in (Celsius, Fahrenheit), so m=180100=95m = \frac{180}{100} = \frac{9}{5} and F=95C+32F = \frac{9}{5}C + 32. If the line passes through the origin, b=0b = 0 and the model is a direct variation y=kxy = kx.

Predicting between your two points (interpolation) is generally safe. Predicting far outside them (extrapolation) assumes the straight-line pattern continues, which real situations often break.

Quick check

A plumber charges 95 dollars for 1 hour and 155 dollars for 3 hours, with cost linear in hours. What does a 5 hour job cost, in dollars?

How do you find a perpendicular bisector from two points?

A perpendicular bisector combines three skills: the midpoint formula, the slope formula, and the rule for perpendicular slopes, which are negative reciprocals. The line passes through the midpoint of the segment, with slope perpendicular to the segment itself.

Example 6. Find the perpendicular bisector of the segment from (1,3)(1, 3) to (5,7)(5, 7).

Midpoint=(1+52,3+72)=(3,5)\text{Midpoint} = \left(\frac{1 + 5}{2}, \frac{3 + 7}{2}\right) = (3, 5)

Segment slope=7−35−1=1⇒perpendicular slope=−1\text{Segment slope} = \frac{7 - 3}{5 - 1} = 1 \quad\Rightarrow\quad \text{perpendicular slope} = -1

y−5=−1(x−3)⇒y=−x+8y - 5 = -1(x - 3) \quad\Rightarrow\quad y = -x + 8

Check that the midpoint is on the line: −3+8=5-3 + 8 = 5. Every point on this line is equally far from (1,3)(1, 3) and (5,7)(5, 7), which is why it appears in geometry constructions and in problems about the point closest to two locations.

Practice problems

0 of 5 solved

  1. Find the equation of the line through (0,4)(0, 4) and (2,10)(2, 10).

  2. Find the equation of the line through (−1,6)(-1, 6) and (3,−2)(3, -2) in slope-intercept form.

  3. Find the equation of the line through (2,3)(2, 3) and (8,6)(8, 6).

  4. Write the line through (−2,1)(-2, 1) and (4,−3)(4, -3) in standard form Ax+By=CAx + By = C with integer coefficients and A>0A > 0.

  5. Find the equation of the perpendicular bisector of the segment with endpoints (−1,2)(-1, 2) and (5,6)(5, 6).

Common questions

What is the formula for the equation of a line through two points?

Find the slope with m=y2−y1x2−x1m = \frac{y_2 - y_1}{x_2 - x_1}, then write y−y1=m(x−x1)y - y_1 = m(x - x_1) using either point. Simplify to y=mx+by = mx + b if you want slope-intercept form.

Does it matter which point you use as (x1,y1)(x_1, y_1)?

No. Both choices give the same line, because both points satisfy the final equation. Pick the point with the friendlier numbers, or the one with x=0x = 0, which hands you the y-intercept directly.

What is the equation of a line if the two points have the same x-coordinate?

The line is vertical and its equation is x=cx = c, where cc is the shared x-value. The slope formula gives a zero denominator, so the slope is undefined and y=mx+by = mx + b does not apply.

How do you find the equation of a line from two points in standard form?

Find the equation in point-slope or slope-intercept form first. Then clear any fractions and move the xx term to the left so you get Ax+By=CAx + By = C, usually with AA positive and all coefficients integers.

How do you find the equation of a line from two points on a graph?

Read the coordinates of two points where the line crosses grid intersections exactly, then apply the slope formula and point-slope form. Points far apart reduce reading errors.

Can two points give more than one line?

No. Two distinct points determine exactly one straight line. The slope is fixed by the two points, and one point then fixes the intercept.

Up next