Algebra

Slope & Line Equation

Given two points, this tool computes the slope m = (y₂ − y₁)/(x₂ − x₁), the y-intercept, and the equation of the line in both slope-intercept (y = mx + b) and point-slope forms. Vertical and horizontal lines are detected automatically.

Slope & Line Equation

Slope, intercept and line equation through two points.

Try:
Answery = 3x − 1
  1. PointsP₁(1, 2), P₂(4, 11)
  2. Slopem = (y₂ − y₁)/(x₂ − x₁) = (11 − 2)/(4 − 1) = 3
  3. y-interceptb = y₁ − m·x₁ = 2 − 3·1 = -1
  4. Slope-intercepty = 3x − 1
  5. Point-slopey − 2 = 3(x − 1)

Two forms, because questions ask for different ones

Two points determine a line, and the line is usually wanted as an equation rather than as a picture. Getting there means one division for the slope, one substitution for the intercept, and a choice of which standard form to write the answer in.

This calculator does all three. It reports the slope, the y-intercept, and the line in both slope-intercept and point-slope form, detecting the vertical case that has neither.

Slope-intercept form is the one to read a graph from: the two numbers are exactly what you need to plot it. Point-slope form is the one that falls out of the working, and it is what a question gives you when it supplies a point and a gradient rather than two points.

Reporting both saves a rearrangement and makes the relationship between them visible. They describe the same line, and converting between them is a matter of expanding a bracket.

How to use this calculator

  1. Enter the first point Its two coordinates in separate fields. This is the point that appears in the point-slope form, so which point you call first affects the presentation.
  2. Enter the second point The same convention. The order does not change the slope, since reversing both differences leaves their ratio alone.
  3. Read the slope first Everything else depends on it. Its sign says whether the line rises or falls, and a magnitude far from what a sketch suggests points to a mistyped coordinate.
  4. Take whichever form the question wants Both describe the same line. Slope-intercept is best for plotting, point-slope for showing working from a given point.

The formula, and where it comes from

m = (y₂ − y₁)/(x₂ − x₁) b = y₁ − m·x₁ y = mx + b y − y₁ = m(x − x₁)

The slope is a rate: how much the vertical coordinate changes per unit of horizontal change. Because both differences reverse when the points are swapped, the ratio is unaffected — which is why the order of the two points never matters for the gradient.

The intercept is found by substituting one point into the line and solving, rather than by any separate formula. Either point works and both give the same answer, which is a free check on the arithmetic.

Point-slope form is the more direct expression of what a line is: from a known point, move along the line at the given rate. Expanding the bracket and collecting turns it into slope-intercept form, so the two are one rearrangement apart.

A vertical line breaks the slope formula, because the horizontal difference is zero and the division is undefined. The solver checks for that before dividing and reports the line as a fixed value of x, which is the only way to describe it — a vertical line is not a function of x and has no slope-intercept form at all.

What each input means

x₁, y₁ First point — form field “x₁”
The point that appears in the point-slope form. Any real coordinates, including negatives.
x₂, y₂ Second point — form field “x₂”
The other point. Interchanging the two leaves the slope and the line unchanged, though the point-slope form is written from the first.
m Slope
The vertical change per unit of horizontal change. Undefined when the two points share an x-coordinate.
b y-intercept
Where the line crosses the vertical axis. Derived by substituting the first point, not measured.

Worked examples

Every number below is produced by the same calculation engine the tool above runs. Nothing here is typed by hand, so the walkthrough cannot drift from what you get when you enter the same values yourself.

A line with positive slope

From (1, 2) to (4, 11). The vertical change is three times the horizontal one, so the line is steep.

Inputs x₁ = 1, y₁ = 2, x₂ = 4, y₂ = 11

  1. Points P₁(1, 2), P₂(4, 11)
  2. Slope m = (y₂ − y₁)/(x₂ − x₁) = (11 − 2)/(4 − 1) = 3
  3. y-intercept b = y₁ − m·x₁ = 2 − 3·1 = -1
  4. Slope-intercept y = 3x − 1
  5. Point-slope y − 2 = 3(x − 1)

Result y = 3x − 1

The differences are 3 across and 9 up, giving a slope of 3. Substituting the first point then gives an intercept of −1, so the line crosses below the origin despite both given points sitting above it.

Substituting the second point instead would give the same intercept. That agreement is worth checking once, since it catches an arithmetic slip in the slope as well as in the substitution.

A horizontal line

From (−2, 3) to (5, 3). The two points share a height, so the line does not rise at all.

Inputs x₁ = -2, y₁ = 3, x₂ = 5, y₂ = 3

  1. Points P₁(-2, 3), P₂(5, 3)
  2. Slope m = (y₂ − y₁)/(x₂ − x₁) = (3 − 3)/(5 − -2) = 0
  3. y-intercept b = y₁ − m·x₁ = 3 − 0·-2 = 3
  4. Slope-intercept y = 3
  5. Point-slope y − 3 = 0(x − -2)

Result y = 3

The slope is zero, not undefined. A zero numerator over a non-zero denominator is a perfectly ordinary division, and the resulting equation is simply a constant height.

The intercept equals that shared height, since a horizontal line meets the vertical axis at its own level. Zero slope and undefined slope are opposite cases and are frequently confused.

A vertical line

From (2, 1) to (2, 7). The two points share an x-coordinate, so the slope formula would divide by zero.

Inputs x₁ = 2, y₁ = 1, x₂ = 2, y₂ = 7

  1. Points P₁(2, 1), P₂(2, 7)
  2. Vertical line Δx = 0, so the slope is undefined.

Result Vertical line: x = 2

The solver detects the zero horizontal difference before dividing and reports the line as a fixed value of x. No slope and no intercept are given, because neither exists.

This line cannot be written as y equals anything: for one value of x it takes every value of y. It is a line but not a function, which is why both standard forms fail on it.

Reading the result

What the slope's sign and size mean

A positive slope rises from left to right and a negative one falls. A magnitude above one is steeper than the diagonal and below one is shallower, and a slope of zero is flat.

Zero slope and undefined slope are opposites

A horizontal line has a slope of exactly zero and a perfectly good equation. A vertical line has no slope at all, because the division that would define it is by zero. Confusing the two is the most common error here.

The intercept can lie far from the data

It is where the line meets the vertical axis, which may be nowhere near either given point. A large intercept from two nearby points is a consequence of a steep slope, not an error.

When you would use this

Turning two measurements into a linear model

Where a quantity changes at a constant rate, two observations fix the relationship completely, and the resulting equation predicts any other value.

Testing whether lines are parallel or perpendicular

Two lines are parallel when their slopes are equal and perpendicular when the slopes multiply to −1. Both tests need the slopes computed first, which is what this returns.

Assumptions and limitations

What this calculator assumes

  • The two points are distinct; identical points determine no line and are rejected.
  • All four coordinates are finite real numbers.
  • The point-slope form is written from the first point supplied.
  • A vertical line is detected before the division and reported as a fixed x-value.

Where it stops being the right tool

  • Two points only: fitting a line to more than two points is regression, not this calculation.
  • The general form with all terms on one side is not reported.
  • No plot is drawn, and no distance between the two points is given.
  • Coefficients are decimals, so a slope of one third appears rounded rather than as a fraction.

Common mistakes

Inverting the slope ratio

Why it happens. Both differences are available and the fraction has to be recalled rather than derived, so run over rise gets written as often as rise over run.

How to avoid it. Check against a sketch. A line that visibly rises quickly must have a slope larger than one in magnitude, not smaller.

Mixing the order of the two points

Why it happens. Taking the vertical difference one way and the horizontal difference the other reverses the sign of the slope while leaving its magnitude right, which is easy to miss.

How to avoid it. Subtract consistently — both differences from the same point. A slope of the wrong sign with the right size is the signature of this error.

Calling a vertical line's slope zero

Why it happens. Both special cases involve a zero somewhere in the fraction, and which one is on top decides between a slope of zero and no slope at all.

How to avoid it. Look at the denominator. A zero horizontal difference makes the slope undefined; a zero vertical difference makes it zero.

Key terms

Frequently asked questions

How is slope calculated?

As the change in the vertical coordinate divided by the change in the horizontal one, taken between the same two points in the same order. Reversing both differences leaves the ratio unchanged, so the order of the points does not matter.

What about a vertical line?

If the two x-coordinates are equal the horizontal difference is zero and the slope is undefined. The solver detects that before dividing and reports the line as x equal to a constant, which is the only form available — a vertical line is not a function of x.

Which line forms are given?

Both slope-intercept and point-slope. The first is best for plotting, since the two numbers are exactly what a sketch needs; the second is what a question supplying a point and a gradient expects. Expanding the bracket converts one into the other.

Is a horizontal line's slope undefined too?

No — it is exactly zero. The vertical difference is zero and the horizontal one is not, which is an ordinary division. Only a vertical line has an undefined slope.