Line Equation Calculator

Get y = mx + b from two points.

How it is calculated

A straight line through two points (x1, y1) and (x2, y2) is written y = mx + b. The slope is m = (y2 − y1) ÷ (x2 − x1), the rise over the run, and the y-intercept is b = y1 − m × x1. The tool shows the slope, the intercept and the finished equation, each rounded to two decimals. If both points have the same x, the line is vertical, the slope is undefined and the tool returns no result; that line is written x = constant instead.

Worked example

Points (1, 3) and (4, 9). Slope: (9 − 3) ÷ (4 − 1) = 6 ÷ 3 = 2.00. Intercept: 3 − 2 × 1 = 1.00. Equation: y = 2.00x + 1.00. Check with the second point: 2 × 4 + 1 = 9, as required.

Try this example →

Common mistakes

  • Subtracting in a different order in numerator and denominator, such as y2 − y1 over x1 − x2. That flips the sign of the slope.
  • Swapping x and y in a pair, so the line is mirrored across the diagonal.
  • Entering two points with the same x and expecting an equation. Vertical lines have no slope-intercept form.
  • Reading the two-decimal rounding as exact. If the slope is 1/3, the printed 0.33 and the intercept are approximations.

About this calculator

Given two points, this calculator finds the slope (m = (y₂−y₁)/(x₂−x₁)) and then solves for the y-intercept to produce the full line equation in slope-intercept form, y = mx + b. Two points with the same x form a vertical line (undefined slope), which gives no result; a horizontal line simply shows a slope of zero.

It's used by students working through algebra and coordinate geometry homework, and by anyone who needs to fit a quick linear trend line through two data points by hand — for example estimating a rate of change between two measurements without pulling up spreadsheet software.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    When you use the line to estimate a third value, plug in the rounded slope and intercept only for a rough guess, since they are shown to two decimals and the error grows the further you extrapolate. A negative intercept is written with a minus sign, so y = 2.00x − 3.00 means y = 2x minus 3. What kind of two measurements are you joining with a line?

Popular calculators

All Calculators