Equation of a line calculator
Enter two points, get the equation of the line.
How do I find the equation of a line through two points?
Find the slope m = (y₂ − y₁) ÷ (x₂ − x₁), then b = y₁ − m × x₁. Through (1, 3) and (4, 9): m = 6 ÷ 3 = 2 and b = 3 − 2 = 1, so y = 2x + 1.
What is point-slope form?
y − y₁ = m(x − x₁), using one of the points: y − 3 = 2(x − 1).
What is standard form?
Ax + By = C with whole numbers and A not negative: y = 2x + 1 becomes 2x − y = −1.
What if both points have the same x?
Then the line is vertical, x = constant, and its slope is undefined.
Where does the line cross the axes?
It crosses the y-axis at b and the x-axis at −b ÷ m: y = 2x + 1 crosses at (0, 1) and (−1/2, 0).
How do I write a line parallel or perpendicular to another line?
Parallel lines have the same slope; perpendicular lines have slopes that are negative reciprocals (OpenStax Intermediate Algebra 2e, section 3.3). For the line perpendicular to y = 2x − 3 through (−2, 1), the slope is −1/2. Enter (−2, 1) and a second point 2 to the right and 1 down, (0, 0), and the calculator returns y = −1/2x, the book's answer.
Why does standard form show different numbers than I expected?
The calculator writes Ax + By = C with whole numbers that share no common factor and A not negative, so the line through (−3, −1) and (2, −2) appears as x + 5y = −8, not −x − 5y = 8 or 0.2x + y = −1.6. All three describe the same line.
How the two-point method works
The slope is the change in y over the change in x, m = (y₂ − y₁) ÷ (x₂ − x₁). Put one point and that slope into point-slope form, y − y₁ = m(x − x₁), and solve for y to get y = mx + b with b = y₁ − m·x₁ (OpenStax Intermediate Algebra 2e, section 3.3). Standard form uses A = y₂ − y₁, B = x₁ − x₂ and C = A·x₁ + B·y₁, scaled to whole numbers. If the points share an x-value the run is zero, the slope is undefined and the line is vertical, x = a, which cannot be written as y = mx + b. A horizontal line has slope 0 and the form y = b. With a slope and one point, step 1 across and m up to get a second point.
Worked example: (−3, −1) and (2, −2)
This is OpenStax Example 3.28. The slope is (−2 − (−1)) ÷ (2 − (−3)) = −1 ÷ 5 = −1/5, and b = −1 − (−1/5)(−3) = −8/5, so the line is y = −1/5x − 8/5. With the second point, point-slope form reads y + 2 = −1/5(x − 2). Standard form is x + 5y = −8, which both points satisfy. The points (−3, 5) and (−3, 4) from Example 3.29 give the vertical line x = −3.
Common mistakes
Subtracting in a different order on top and bottom flips the sign: (−2 − (−1)) ÷ (−3 − 2) gives 1/5 instead of −1/5. In point-slope form a negative y₁ turns the minus into a plus, so y₁ = −2 gives y + 2, not y − 2. A vertical line has an undefined slope, not a slope of zero; zero belongs to horizontal lines. And rounding a slope such as 2/3 to 0.67 before finding b shifts the intercept, so keep fractions until the end.
Sources: OpenStax, Intermediate Algebra 2e, section 3.3 “Find the Equation of a Line” (Examples 3.28, 3.29 and 3.31). Related tools: slope calculator, midpoint calculator, distance formula calculator and system of equations calculator. How we check our calculators.