Math
Equation of a straight line calculator
Choose what you know about the line (two points, a point and its slope, its intercepts, or a line it must be parallel or perpendicular to) and get its equation in all four standard forms, with exact fractions and the working shown.
A fraction such as 3/4 is fine.
Any linear form: y = 2x + 1, 3x − 4y = 5, x = 2.
| Form | Equation |
|---|---|
| Slope-intercept (y = mx + c) | y = −2x + 3 |
| Point-slope (y − y₁ = m(x − x₁)) | y − 5 = −2(x + 1) |
| General (ax + by + c = 0) | 2x + y − 3 = 0 |
| Intercept (x/a + y/b = 1) | x/(3/2) + y/3 = 1 |
Show the working, step by step
Slope from the two points: m = (y₂ − y₁) ÷ (x₂ − x₁).
m = (−3 − 5) ÷ (3 − (−1)) = −8 ÷ 4 = −2
Rearrange into the other forms.
slope-intercept: y = −2x + 3 general: 2x + y − 3 = 0 intercept: x/(3/2) + y/3 = 1
The four forms
Slope-intercept: y = mx + c Point-slope: y − y₁ = m(x − x₁) General: ax + by + c = 0 Intercept: x/a + y/b = 1
All four describe the same line. Slope-intercept shows the gradient and where the line crosses the y-axis. Point-slope is the quickest to write down from a point and a slope. General form is what distance and intersection formulas expect, and it handles vertical lines. Intercept form shows both axis crossings at once.
A worked example
The calculator opens with the points (−1, 5) and (3, −3).
- Slope: m = (−3 − 5) ÷ (3 − (−1)) = −8 ÷ 4 = −2.
- Point-slope with (−1, 5): y − 5 = −2(x + 1).
- Expand: y = −2x − 2 + 5, so y = −2x + 3.
- General form: 2x + y − 3 = 0.
- Intercepts: y = 0 gives x = 3/2, and x = 0 gives y = 3, so x/(3/2) + y/3 = 1.
The other modes open on the same line so you can compare them. Slope −2 through (−1, 5), slope −2 with y-intercept 3, and intercepts 3/2 and 3 all give y = −2x + 3. So does the line through (−1, 5) perpendicular to x − 2y + 4 = 0, because that line has slope 1/2 and (1/2) × (−2) = −1.
Which method to use
| You know | Start from |
|---|---|
| Two points | m = (y₂ − y₁)/(x₂ − x₁), then point-slope |
| A point and the slope | y − y₁ = m(x − x₁) |
| The slope and the y-intercept | y = mx + c directly |
| Both intercepts | x/a + y/b = 1 |
| A point and a parallel line | Same a and b as the given line, new c |
| A point and a perpendicular line | Swap a and b, change one sign, new c |
Common mistakes
- Sign slips in point-slope form. For the point (−1, 5) the bracket is (x + 1), not (x − 1).
- Leaving fractions in the general form. Multiply through so a, b and c are whole numbers with no common factor.
- Using the negative slope for a perpendicular line. The perpendicular slope is the negative reciprocal, −1/m. For m = 1/2 that is −2, not −1/2.
- Reading c in ax + by + c = 0 as the y-intercept. The y-intercept is −c/b. For 2x + y − 3 = 0 it is 3.
Common questions
How do you find the equation of a line through two points?
Find the slope m = (y₂ − y₁)/(x₂ − x₁), then substitute one point into y − y₁ = m(x − x₁) and rearrange. Through (−1, 5) and (3, −3): m = −8/4 = −2, so y − 5 = −2(x + 1), which gives y = −2x + 3, or 2x + y − 3 = 0.
What is the general form of a straight line?
ax + by + c = 0, usually written with whole-number coefficients, no common
factor and a positive leading coefficient. Unlike y = mx + c it can describe vertical lines
(b = 0). Clear fractions by multiplying through by the lowest common denominator:
y = (2/3)x − 7/3 becomes 2x − 3y − 7 = 0.
What is the intercept form of a line?
x/a + y/b = 1, where a is the x-intercept and b is the y-intercept. The line
y = −2x + 3 crosses the axes at (3/2, 0) and (0, 3), so its intercept form is
x/(3/2) + y/3 = 1. Lines through the origin have no intercept form, because both intercepts
are 0.
How do I find a line parallel or perpendicular to a given line?
A parallel line keeps the same x and y coefficients: parallel to x − 2y + 4 = 0 means x − 2y + k = 0. A perpendicular line swaps them and changes one sign: 2x + y + k = 0. Then put the given point in to find k. Through (−1, 5): the parallel line is x − 2y + 11 = 0 and the perpendicular line is 2x + y − 3 = 0.
What is the slope of a vertical line?
It is undefined, because the run x₂ − x₁ is zero. A vertical line has the equation x = constant and cannot be written as y = mx + c. A horizontal line has slope 0 and equation y = constant.
Related calculators
-
Line calculator
Intersection, angle and distance between two lines.
-
Distance and midpoint
Distance, midpoint and slope between two points.
-
Linear equation calculator
Solve linear equations step by step.
-
Linear regression
The best-fit straight line through a set of data points.