Part 8 of 10 · LinesSee the whole course

How to find the equation of a line from two points

Short answer

Find the slope from the two points, then put one point into y = mx + b to find b. Write m and b into the equation, and check it with the other point.

The four steps

  1. Find the slope. m = (y₂ − y₁) ÷ (x₂ − x₁), with the points in the same order on the top and the bottom. (If that is new, see how to find the slope from two points.)
  2. Find b. Put m and one of the points into y = mx + b, then solve for b.
  3. Write the equation. Replace m and b in y = mx + b.
  4. Check. Put the other point in. If the equation is true, you are done.

Try it. Point A stays at (1, 2). Move point B and watch the three steps change.

y = 3x − 1
  1. slope = (8 − 2) ÷ (3 − 1) = 3
  2. b = 2 − 3 × 1 = −1
  3. y = 3x − 1
Point A is (1, 2). Move point B and the equation follows.

Example 1: (1, 2) and (3, 8)

Slope: (8 − 2) ÷ (3 − 1) = 6 ÷ 2 = 3
Find b: 2 = 3(1) + b, so b = −1
Equation: y = 3x − 1
Check (3, 8): 3(3) − 1 = 8 ✓

This is the picture above, in its starting position.

Example 2: with negative numbers, (−2, 5) and (4, −1)

Slope: (−1 − 5) ÷ (4 − (−2)) = −6 ÷ 6 = −1
Find b: 5 = (−1)(−2) + b, so 5 = 2 + b and b = 3
Equation: y = −x + 3
Check (4, −1): −4 + 3 = −1 ✓

Put brackets around negative numbers when you substitute. (−1)(−2) is +2, and that is where most sign slips happen.

Example 3: when the line is vertical, (2, 1) and (2, 7)

Both points have x = 2, so the run is 2 − 2 = 0 and the slope is undefined. A vertical line cannot be written as y = mx + b. It is simply x = 2: every point on it has x equal to 2. (More on this in our post on horizontal and vertical lines.)

Why one point is enough for b

The slope says how steep the line is, but not where it sits. One point pins it down. Once you know the slope and one point that is on the line, there is only one line it can be, so the other point is not needed for finding b. It is your check.

You may also see the point-slope form, y − y₁ = m(x − x₁). For Example 1 it is y − 2 = 3(x − 1). Expand it and you get the same y = 3x − 1.

Watch it explained in under a minute

The same idea, narrated step by step. Square version for sharing: download the 1:1 video.

The five mistakes to avoid

Try it yourself

Find the equation of the line through each pair of points. Tap a question to see the answer.

1. (0, 3) and (2, 7)

Slope: (7 − 3) ÷ (2 − 0) = 2. The point (0, 3) is on the y-axis, so b = 3. y = 2x + 3. Check (2, 7): 4 + 3 = 7 ✓.

2. (1, 5) and (3, 1)

Slope: (1 − 5) ÷ (3 − 1) = −2. Then 5 = (−2)(1) + b, so b = 7. y = −2x + 7. Check (3, 1): −6 + 7 = 1 ✓.

3. (2, 4) and (6, 6)

Slope: (6 − 4) ÷ (6 − 2) = 2 ÷ 4 = ½. Then 4 = ½(2) + b, so b = 3. y = ½x + 3. Check (6, 6): 3 + 3 = 6 ✓.

Where this fits in

You now go both ways: from an equation to a graph (graph a line from its equation) and from two points back to an equation. The next post covers the two special cases that do not fit the pattern: horizontal and vertical lines.

Quick answers

Questions about this topic

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

Find the slope with (y₂ − y₁) ÷ (x₂ − x₁), then put the slope and one point into y = mx + b and solve for b. Write m and b into the equation and check it with the other point.

What if the two points have the same x-value?

Then the line is vertical, the slope is undefined, and the equation is x = that number. A vertical line cannot be written as y = mx + b.

Do I need both points to find b?

No. After you have the slope, one point is enough to find b. The second point is useful as a check.

What is point-slope form?

Point-slope form is y − y₁ = m(x − x₁). It uses the slope and one point directly. If you expand it and solve for y, you get the same y = mx + b.

Keep going

Learn it by playing

Pip: Math Adventure is a math game for iPhone where functions, lines, equations and calculus are puzzles you solve by playing. It is coming soon to the App Store.

Join the list and we will tell you the day Pip is out.