Algebra 1 · Grades 8, 9

How to Write the Equation of a Line from Two Points

Quick answer

To find the equation of a line through two points, first compute the slope with the slope formula, then substitute that slope and either point into point-slope form, then simplify. Through (1, 3) and (3, 7) the slope is 2, giving y - 3 = 2(x - 1), which simplifies to y = 2x + 1.

What you'll learn

  • Find the equation of a line through two given points
  • Combine the slope formula with point-slope form
  • Handle the special cases of horizontal and vertical lines

The whole method in one line

Two points determine a line, so they must determine its equation. Getting there is two tools you already have, used in order:

two points  → slope formula   m  → point-slope   equation\text{two points} \;\xrightarrow{\text{ slope formula }}\; m \;\xrightarrow{\text{ point-slope }}\; \text{equation}
  1. Compute the slope: m=y2−y1x2−x1m = \tfrac{y_2 - y_1}{x_2 - x_1}.
  2. Substitute mm and either point into y−y1=m(x−x1)y - y_1 = m(x - x_1).
  3. Simplify to slope-intercept form if you want the intercept.

Why you need the slope first

Point-slope form needs a slope, and you are not given one — you are given two points. So the slope formula comes first, and its answer feeds the second step.

It is worth seeing that this always works. Two distinct points with different xx-values give exactly one slope, and a slope plus a point gives exactly one line. So the answer exists and is unique — there is never a choice to agonize over, only arithmetic to do carefully.

Two points fix exactly one line Two marked points at (1, 3) and (4, 9), with a single straight line passing through both and continuing beyond them. −22468510xy (1, 3) (4, 9)
  • the only line through both
Two points fix exactly one line

You could not draw a second straight line through both of those dots if you tried. That is the whole reason the method has no choices in it.

The calculator below writes the line through (1,3)(1, 3) and (3,7)(3, 7) in point-slope form and slope-intercept form, the same way as Example 1.

Point-slope form calculator

Describe a line by a slope and a point, by two points, or by its equation, and see it written as y−y1=m(x−x1)y - y_1 = m(x - x_1), then expanded, checked and graphed. Choose how the line is given and fill in the boxes that choice uses. Whole numbers, decimals and fractions all work.

The steps below work this lesson's example. Turn on JavaScript to try your own numbers.

Worked example: through (1,3) and (3,7)

Point-slope form: y − 3 = 2(x − 1), with slope 2 through (1, 3). In slope-intercept form: y = 2x + 1.

Graph of y = 2x + 1 A straight line that rises from left to right with slope 2. It crosses the y-axis at (0, 1) and the x-axis at (−1/2, 0). Marked points: (1, 3) and (3, 7). −4−2246−22468xy (1, 3) (3, 7) (−1/2, 0) (0, 1)
  • y = 2x + 1
Graph of y = 2x + 1

Label the points

Call the first point (x1,y1) and the second (x2,y2).

(x1,y1)=(1,3)(x2,y2)=(3,7)

Substitute, subtract and simplify

Put the y-values on top and the x-values on the bottom, both starting from the same point.

m=y2−y1x2−x1=7−33−1=42=2

What it tells you

The slope is positive, so the line rises from left to right.

Choose one of the points

Use (1,3). The other point gives the same line.

Substitute into point-slope form

Put m=2, x1=1 and y1=3 into the form.

y−y1=m(x−x1)
y−3=2(x−1)

Expand to slope-intercept form

Distribute m=2 across the brackets.

y−3=2x−2

Add 3 to both sides to get y alone.

y=2x+1

Check

Test both points in the slope-intercept form. Checking only the point you substituted proves nothing.

At x=1:

y=2(1)+1=2+1=3

At x=3:

y=2(3)+1=6+1=7

The same line in other forms

Standard form, with whole-number coefficients and A not negative:

2x−y=−1

Intercepts and graph

Set y=0 to find where the line crosses the x-axis.

2x=−1x=−12=−12

Set x=0 to find where it crosses the y-axis.

−y=−1y=1

The line crosses the x-axis at (−12,0) and the y-axis at (0,1).

A straight line that rises from left to right with slope 2. It crosses the y-axis at (0, 1) and the x-axis at (−1/2, 0). Marked points: (1, 3) and (3, 7).

Runs on your device: nothing you type is sent or saved. Want the reasoning behind each step? Read the point-slope form lesson, or see how to write the equation of a line from two points.

Worked examples

Common mistakes

Practice problems

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

    Hint

    Compute the slope first. One of these points is already the yy-intercept.

    Answer

    y=2x+2y = 2x + 2

    Full solution

    m=10−24−0=84=2m = \tfrac{10 - 2}{4 - 0} = \tfrac{8}{4} = 2.

    Since (0,2)(0, 2) is the yy-intercept, b=2b = 2 and y=2x+2y = 2x + 2 directly.

    Check at x=4x = 4: y=10y = 10 ✓

  2. Find the equation of the line through (1,5)(1, 5) and (3,11)(3, 11).

    Answer

    y=3x+2y = 3x + 2

    Full solution

    m=11−53−1=3m = \tfrac{11 - 5}{3 - 1} = 3. Using (1,5)(1, 5): y−5=3(x−1)=3x−3y - 5 = 3(x - 1) = 3x - 3, so y=3x+2y = 3x + 2.

    Check at x=3x = 3: y=11y = 11 ✓

  3. Find the equation of the line through (−1,4)(-1, 4) and (2,−2)(2, -2).

    Answer

    y=−2x+2y = -2x + 2

    Full solution

    m=−2−42−(−1)=−63=−2m = \tfrac{-2 - 4}{2 - (-1)} = \tfrac{-6}{3} = -2.

    Using (2,−2)(2, -2): y+2=−2(x−2)=−2x+4y + 2 = -2(x - 2) = -2x + 4, so y=−2x+2y = -2x + 2.

    Check at x=−1x = -1: y=2+2=4y = 2 + 2 = 4 ✓

  4. Find the equation of the line through (3,−1)(3, -1) and (8,−1)(8, -1).

    Hint

    Compute the slope before reaching for point-slope form.

    Answer

    y=−1y = -1

    Full solution

    m=−1−(−1)8−3=05=0m = \tfrac{-1 - (-1)}{8 - 3} = \tfrac{0}{5} = 0, so the line is horizontal at the shared height: y=−1y = -1.

  5. Find the equation of the line through (−2,3)(-2, 3) and (−2,9)(-2, 9).

    Answer

    x=−2x = -2

    Full solution

    The xx-values match, so the denominator is 00 and the slope is undefined. The line is vertical: x=−2x = -2.

  6. Find the equation of the line through (0,−3)(0, -3) and (6,1)(6, 1).

    Hint

    Expect a fractional slope. Keep it as a fraction.

    Answer

    y=23x−3y = \tfrac{2}{3}x - 3

    Full solution

    m=1−(−3)6−0=46=23m = \tfrac{1 - (-3)}{6 - 0} = \tfrac{4}{6} = \tfrac{2}{3}.

    (0,−3)(0, -3) is the intercept, so y=23x−3y = \tfrac{2}{3}x - 3.

    Check at x=6x = 6: y=4−3=1y = 4 - 3 = 1 ✓

  7. Two students find the line through (2,1)(2, 1) and (5,7)(5, 7). One writes y−1=2(x−2)y - 1 = 2(x - 2), the other writes y−7=2(x−5)y - 7 = 2(x - 5). Who is right?

    Hint

    Simplify both.

    Answer

    Both.

    Full solution

    First: y−1=2x−4y - 1 = 2x - 4, so y=2x−3y = 2x - 3.

    Second: y−7=2x−10y - 7 = 2x - 10, so y=2x−3y = 2x - 3.

    They used different points, which is allowed, and reached the same line.

  8. A plant is measured at 1212 cm on day 33 and 2727 cm on day 88. Assuming steady growth, write an equation for its height and predict its height on day 1212.

    Hint

    Days are xx, height is yy. Find the growth rate first.

    Answer

    y=3x+3y = 3x + 3; on day 1212 it is 3939 cm.

    Full solution

    m=27−128−3=155=3m = \tfrac{27 - 12}{8 - 3} = \tfrac{15}{5} = 3 cm per day.

    Using (3,12)(3, 12): y−12=3(x−3)=3x−9y - 12 = 3(x - 3) = 3x - 9, so y=3x+3y = 3x + 3.

    On day 1212: y=36+3=39y = 36 + 3 = 39 cm.

    The intercept 33 predicts a height of 33 cm on day 00, which is a reasonable seedling — but predicting far outside the measured range assumes growth stays steady, and real plants eventually stop.

Frequently asked questions

Which of the two points should I substitute?

Either. Both give equations that simplify to the same line. Pick the one with smaller or positive numbers, since it makes the arithmetic cleaner.

What if the two points give a slope of zero?

Then the line is horizontal and its equation is y = the shared y-value. There is no need for point-slope form; the answer is already in front of you.

What if the x-values are the same?

Then the slope is undefined and the line is vertical. Its equation is x = the shared x-value. A vertical line cannot be written as y = mx + b at all.

What to learn next

Formulas on this page

Standards alignment

This lesson covers the following Common Core State Standards for Mathematics.

  • CCSS.MATH.CONTENT.HSA.CED.A.2Creating EquationsCreate equations in two or more variables to represent relationships between quantities; graph equations on coordinate axes with labels and scales.
  • CCSS.MATH.CONTENT.8.EE.B.6Expressions and EquationsUse similar triangles to explain why the slope m is the same between any two distinct points on a non-vertical line in the coordinate plane; derive the equation y = mx for a line through the origin and the equation y = mx + b for a line intercepting the vertical axis at b.