Skip to main content
Online
Algebra · step-by-step

Slope and Line Equation Calculator

Enter two points to get the slope with every step, the equation of the line in slope-intercept, point-slope and standard form, the distance and midpoint, and a graph. Fractions stay exact.

Enter two points. Integers, decimals and fractions such as -3/2 are accepted.

Complete guide

Slope and the equation of a line: from two points to y = mx + b

5 min read Reviewed By the GetCalcMaster team · Editorial policy

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

  1. Enter the coordinates of the first point as x₁ and y₁, and the second point as x₂ and y₂. Fractions such as -3/2 and decimals are fine.
  2. 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.
  3. Use Copy link to share exactly this problem; the link reopens the solver with your numbers filled in.

Key formulas

Slope (rise over run)
m = (y₂ − y₁) / (x₂ − x₁)
The change in y divided by the change in x. Subtract in the same order on the top and the bottom.
Slope-intercept form
y = mx + b
m is the slope and b is the y-intercept, the value of y where the line crosses the y-axis.
Point-slope form
y − y₁ = m(x − x₁)
Fastest to write down when you know one point and the slope.
Standard form
Ax + By = C
Usually written with whole-number coefficients and A ≥ 0. It is the only form that also covers vertical lines (B = 0).
Distance between two points
d = √((x₂ − x₁)² + (y₂ − y₁)²)
The Pythagorean theorem applied to the run and the rise.
Midpoint
M = ((x₁ + x₂)/2, (y₁ + y₂)/2)
The average of the x-coordinates and the average of the y-coordinates.
Parallel and perpendicular
m₁ = m₂ · m₁ · m₂ = −1
Parallel lines share a slope; perpendicular slopes are negative reciprocals (unless one line is vertical).

Worked examples

Example 1: A line with a negative slope

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

  1. m = (−1 − 5) / (4 − (−2)) = −6 / 6 = −1.
  2. Substitute (−2, 5): 5 = (−1)(−2) + b, so b = 3.
  3. Check with (4, −1): (−1)(4) + 3 = −1 ✔.
Answer: y = −x + 3, or x + y = 3 in standard form. The distance between the points is √72 = 6√2 ≈ 8.485 and the midpoint is (1, 2).
Try it: line through (-2, 5) and (4, -1)
Example 2: Fractional coordinates, kept exact

Find the line through (1/2, 3) and (2, −3/2).

  1. Rise: −3/2 − 3 = −9/2. Run: 2 − 1/2 = 3/2.
  2. m = (−9/2) ÷ (3/2) = −3.
  3. b = 3 − (−3)(1/2) = 3 + 3/2 = 9/2.
  4. Standard form: multiply y = −3x + 9/2 by 2 and rearrange to 6x + 2y = 9.
Answer: y = −3x + 9/2 (standard form 6x + 2y = 9).
Example 3: A vertical line

Find the line through (3, −1) and (3, 6).

  1. The run is 3 − 3 = 0, so the slope (7 / 0) is undefined.
  2. Both points have x = 3, and so does every other point on the line.
Answer: x = 3. A vertical line cannot be written as y = mx + b.
Example 4: A horizontal line

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

  1. The rise is 2 − 2 = 0, so m = 0 / 9 = 0.
  2. b = 2 − 0 · (−4) = 2.
Answer: y = 2: every point on the line has height 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?
Find the slope with m = (y₂ − y₁)/(x₂ − x₁), substitute one point into y = mx + b to find b, then write y = mx + b. Check by substituting the other point.
What does an undefined slope mean?
It means the run is zero: both points have the same x-coordinate and the line is vertical. Its equation is x = constant.
Can a slope be a fraction?
Yes. Most slopes are fractions. A slope of 3/4 means the line rises 3 units for every 4 units to the right. Keeping it as a fraction avoids rounding errors in the intercept.
How can I tell if two lines are perpendicular?
Multiply their slopes. If the product is −1 the lines are perpendicular. The exception is a vertical line and a horizontal line, which are perpendicular even though the vertical slope is undefined.
Is gradient the same as slope?
Yes. “Gradient” is the usual word in the UK and many other countries; “slope” is more common in the US. Both mean rise over run.

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.