Slope and the equation of a line: from two points to y = mx + b
Two points are enough to fix a straight line, and the slope is the single number that describes how steep that line is. Slope shows up far beyond algebra class: it is the speed in a distance–time graph, the price per item in a cost graph, and the grade of a road. This guide explains how to find the slope from two points, how to turn it into the equation of the line in each of the standard forms, and how to handle the special cases that trip people up.
The calculator above keeps fractions exact, so a slope of 2/3 stays 2/3 instead of 0.6667, and it checks the final equation by substituting the second point back in.
How to use this tool
- Enter the coordinates of the first point as x₁ and y₁, and the second point as x₂ and y₂. Fractions such as
-3/2and decimals are fine. - Press Solve step by step. The solution shows the slope, the y-intercept, the line in three forms, a check, the distance, the midpoint and a graph.
- Use Copy link to share exactly this problem; the link reopens the solver with your numbers filled in.
Key formulas
m = (y₂ − y₁) / (x₂ − x₁)y = mx + by − y₁ = m(x − x₁)Ax + By = Cd = √((x₂ − x₁)² + (y₂ − y₁)²)M = ((x₁ + x₂)/2, (y₁ + y₂)/2)m₁ = m₂ · m₁ · m₂ = −1Worked examples
Find the equation of the line through (−2, 5) and (4, −1).
- m = (−1 − 5) / (4 − (−2)) = −6 / 6 = −1.
- Substitute (−2, 5): 5 = (−1)(−2) + b, so b = 3.
- Check with (4, −1): (−1)(4) + 3 = −1 ✔.
line through (-2, 5) and (4, -1)Find the line through (1/2, 3) and (2, −3/2).
- Rise: −3/2 − 3 = −9/2. Run: 2 − 1/2 = 3/2.
- m = (−9/2) ÷ (3/2) = −3.
- b = 3 − (−3)(1/2) = 3 + 3/2 = 9/2.
- Standard form: multiply y = −3x + 9/2 by 2 and rearrange to 6x + 2y = 9.
Find the line through (3, −1) and (3, 6).
- The run is 3 − 3 = 0, so the slope (7 / 0) is undefined.
- Both points have x = 3, and so does every other point on the line.
Find the line through (−4, 2) and (5, 2).
- The rise is 2 − 2 = 0, so m = 0 / 9 = 0.
- b = 2 − 0 · (−4) = 2.
Reading slope as a rate of change
The slope tells you how much y changes when x increases by one unit. A slope of 3 means “up 3 for every 1 to the right”; a slope of −1/2 means “down 1 for every 2 to the right”. When the axes have units, the slope has units too: kilometers per hour, dollars per item, degrees per minute. Writing those units next to the slope is the quickest way to see what a graph is telling you.
Positive slopes rise from left to right, negative slopes fall, a zero slope is flat, and an undefined slope is vertical. The bigger the absolute value, the steeper the line: a slope of −5 is steeper than a slope of 2.
Which form of the equation should you use?
All three forms describe the same line; they are just convenient for different jobs.
| Form | Looks like | Best for |
|---|---|---|
| Slope-intercept | y = mx + b | Graphing quickly and reading the slope and intercept |
| Point-slope | y − y₁ = m(x − x₁) | Writing the line straight from a point and a slope |
| Standard | Ax + By = C | Vertical lines, integer coefficients and solving systems by elimination |
Special cases
- Same point twice: one point does not determine a line, because infinitely many lines pass through it. The solver asks for two different points.
- Vertical line (x₁ = x₂): the slope is undefined and the equation is x = x₁.
- Horizontal line (y₁ = y₂): the slope is 0 and the equation is y = y₁.
- Through the origin: b = 0, so the equation is simply y = mx. The quantities are directly proportional.
Common mistakes to avoid
- Subtracting in a different order on the top and the bottom, e.g. (y₂ − y₁)/(x₁ − x₂), which flips the sign of the slope.
- Dividing run by rise instead of rise by run.
- Dropping a negative sign when subtracting a negative coordinate: 4 − (−2) is 6, not 2.
- Calling the slope of a vertical line 0. A slope of 0 is horizontal; a vertical line has an undefined slope.
- Taking just the negative of a slope for a perpendicular line. The perpendicular slope is the negative reciprocal: for m = 2/3 it is −3/2.
Frequently asked questions
How do you find the equation of a line from two points?
What does an undefined slope mean?
Can a slope be a fraction?
How can I tell if two lines are perpendicular?
Is gradient the same as slope?
Related tools and guides
References
Educational content. Results are computed in your browser with standard double-precision arithmetic; double-check anything with legal, financial, medical, or safety consequences. Spotted an error? Tell us and we will correct it.