A straight line on a coordinate grid contains enough information to write its equation. For a nonvertical line, find its slope (how much y changes per unit of x) and y-intercept (where it meets the y-axis). Put those values into y = mx + b. If the line is vertical, its equation is x = a constant instead.

Read a straight-line graph

A point is written as (x, y). Read the horizontal coordinate first, then the vertical coordinate. Choose two points where the line passes exactly through grid intersections. Count the units using the numbers on the axes; a square does not always mean one unit.

The slope m tells how steep the line is and whether it rises or falls as you move right. The y-intercept b is the y-coordinate at x = 0.

xy0-5-5-4-4-2-2224455(0, −1)(2, 3)
Move right 2 and up 4 between the two marked points.

Calculate rise and run

Find the vertical change (rise) and divide by the horizontal change (run). Choose the same order in both differences:

m = y₂ − y₁x₂ − x₁

For the graph above, rise = 3 − (−1) = 4 and run = 2 − 0 = 2, so m = 4 ÷ 2 = 2. If you move right and down, the rise is negative and the slope is negative. A horizontal line has zero rise. A vertical line has zero run, so division is undefined.

Find the intercept and write the equation

Read b from the crossing at x = 0. In the graph, b = −1, giving y = 2x − 1. Check the second point: 2(2) − 1 = 3. If the crossing is outside the drawn grid, use a known point in y = mx + b and solve for b.

Suppose two points are (2, 5) and (5, 11). The slope is 6 ÷ 3 = 2. Substitute (2, 5): 5 = 2(2) + b, so b = 1. The equation y = 2x + 1 matches both points. The y-intercept is not simply the first y-value; it is the output when x = 0.

A horizontal line through (4, −3) has y = −3. A vertical line through (4, −3) has x = 4. Two different points determine a unique line, but a single point can lie on infinitely many lines.

Examples

Example 1: Read the intercept first

A graph crosses the y-axis at 4 and also passes through (3, 1). Slope = (1 − 4) ÷ 3 = −1. Its equation is y = −x + 4. At x = 3, y = 1.

Example 2: Use a graph without the intercept

The visible points are (−3, 2) and (1, 4). Slope = 2 ÷ 4 = 12. Substitute (1, 4) into y = mx + b: b = 4 − 12 = 72. Therefore y = 12x + 72.

Example 3: Recognize a vertical line

The points (−2, 0) and (−2, 5) share the same x-coordinate. Run = 0, so slope is undefined. Every point on the line has x = −2, giving x = −2.

Video lessons

Equation from two graph points

Choose two distinct grid points. This builder finds the exact slope and equation, including horizontal and vertical cases.

Exercises

Try the ten questions on your own. If an answer is not right, use the hint and try again before moving on.

Interactive practiceQuestion 1 of 10
Read the two marked points and the axis labels. Which equation matches the line?
0 of 10 answered

Printable practice

Want to work on paper? These free worksheets include practice and an answer key.

Frequently asked questions

Can I find a line from two points without seeing the y-intercept?

Yes. Find the slope from the two coordinate differences, then substitute either point to solve for b.

What if one point is the origin?

A nonvertical line through the origin has b = 0, so y = mx. A vertical line through the origin has equation x = 0; it is the entire y-axis.

Why is x = 4 not in slope-intercept form?

It is vertical and its slope is undefined. All points have x = 4.

Related topics