Line Equation From Two Points Calculator
Written by Thierno Sadou Diallo, formula verified per our methodology • Last checked on 9/10/2026
The equation of a line through two points (x1,y1) and (x2,y2) is written y = mx + b, with slope m = (y2−y1)/(x2−x1) and y-intercept b = y1 − m×x1. For the points (0,2) and (4,10), the equation is y = 2x + 2.
Explanation
Two distinct points always suffice to define a unique line, and knowing their coordinates lets you recover its equation directly in slope-intercept form y = mx + b — the most used form because it immediately gives two key pieces of information: the slope m, which tells how much y increases when x increases by one unit (a positive slope means the line goes up from left to right, a negative slope that it goes down), and the y-intercept b, the value of y where the line crosses the vertical axis (x=0). The slope is calculated as the ratio of the change in y to the change in x between the two points; the y-intercept then follows by substituting one of the two points' coordinates back into the equation. This same ratio of changes is at the heart of other analytic geometry calculations, such as the distance between two points (which combines the same coordinate differences, but under a square root rather than a simple ratio) or the distance from a point to a line, which assumes the line's equation is already known. One special case deserves attention: if the two points have the same x-coordinate (x1 = x2), the line connecting them is vertical and has no defined slope in the usual sense — it then cannot be written in the form y = mx + b, only in the form x = constant.
Example: line through (0,2) and (4,10)
Inputs
First point: (0, 2). Second point: (4, 10).
Calculation
m = (10 − 2) ÷ (4 − 0) = 8 ÷ 4 = 2. b = 2 − (2 × 0) = 2. Equation: y = 2x + 2.
Result
The line through these two points has the equation y = 2x + 2.
Frequently asked questions
What happens if the two points have the same x-coordinate?
The line connecting them is then vertical, and its slope would be mathematically infinite (division by zero in the calculation of m): a vertical line cannot be expressed in the form y = mx + b, only in the form x = a constant. This calculator flags this case rather than showing an erroneous result.
What does the y-intercept represent concretely?
It is the value of y where the line crosses the vertical axis, that is, when x = 0. On a graph, if the y-intercept is 2, the line passes through the point (0, 2) — an immediate visual reference for drawing the line by hand once its equation is known.
Can you recover the equation using the other point rather than the first?
Yes, the result is exactly identical whichever point is used to calculate the y-intercept, since both points belong by definition to the same line: substituting (x2, y2) into y2 − m×x2 gives exactly the same value of b, up to computational precision.