Skip to content
CALX
Appearance

Appearance

Light or dark

Colour
Accessibility

Equation of a line calculator

y = mx + b from two points or a slope and a point: slope, y-intercept, root, vertical line included.

Parameters

Point A
Point B

Result

Equation of the line

y = −0.5x + 3

Calculation
m = Δy / Δx = −3 / 6 = −0.5
Calculation
b = y₁ − m·x₁ = 3 − (−0.5) × 0 = 3
02460123xy
Slope
−0.5
y-intercept
3
x-intercept (root)
6
Slope of a perpendicular
2
Note

The equation of the line is y = −0.5x + 3.

Calculation, assumptions and sources

OverviewSlope-intercept equation y = mx + b of a line given by two points, or by its slope and one point: slope (m = Δy / Δx), y-intercept, root, slope of a perpendicular and y at a chosen x.

Slope-intercept equation y = mx + b of a line given by two points, or by its slope and one point: slope (m = Δy / Δx), y-intercept, root, slope of a perpendicular and y at a chosen x. A vertical line is written x = c; two coinciding points are rejected.

Method & formulasm = (y₂ − y₁) / (x₂ − x₁)
m = (y₂ − y₁) / (x₂ − x₁)b = y₁ − m·x₁root: x = −b / mperpendicular: m⊥ = −1 / m

The slope comes from the increments, then the y-intercept from making the line pass through one of the points. The other point must give the same value of b.

Slope
the change in y when x increases by 1. Positive, the line climbs; negative, it drops; zero, it is horizontal.
y-intercept
the y of the point where the line crosses the vertical axis, at x = 0.
x-intercept (root)
the x where the line crosses the horizontal axis, solution of mx + b = 0.
Linear (affine) function
x ↦ mx + b, proportional if b = 0 (line through the origin).
Validity domainCartesian plane, exact coordinates: the line passes through the given points, with no fitting; noisy measured points call for linear regression.

Cartesian plane, exact coordinates: the line passes through the given points, with no fitting; noisy measured points call for linear regression. With two very close points, the slope becomes highly sensitive to input rounding: for points 10⁻⁷ apart, a hundredth of error on y moves it by several orders of magnitude.

The vertical caseTwo points with the same abscissa define the line x = c.

Two points with the same abscissa define the line x = c. It is not the graph of a function (one x, many y), and the slope formula would divide by zero. The result is x = c, with no slope.

Reading the resultTwo lines are parallel if they share the same slope, perpendicular if the product of their slopes is −1.

Two lines are parallel if they share the same slope, perpendicular if the product of their slopes is −1. A horizontal and a vertical line are perpendicular without satisfying this rule, since the vertical has no slope.