Home / Math / Slope Calculator
Slope Calculator: Find the Slope of a Line From Two Points
Enter the coordinates of two points and get the slope (rise over run), the equation of the line through them, the y-intercept, the angle of inclination and the slope of a perpendicular line.
The slope formula
The slope of a straight line measures how much it rises or falls for each unit you move to the right. For two points (x1, y1) and (x2, y2) the formula is:
m = (y2 − y1) ÷ (x2 − x1)
The top part is the rise and the bottom part is the run. Because a straight line has the same steepness everywhere, any two distinct points on it give the same answer. It does not matter which point you call first, as long as you subtract in the same order on the top and the bottom. Swapping both gives the same fraction with both signs flipped, so the result is unchanged.
Once the slope is known, the y-intercept comes from b = y1 − m × x1, which gives the slope-intercept form y = mx + b.
How to read the result
- Positive slope: the line climbs as you move right. A slope of 2 means y rises by 2 for every 1 step in x.
- Negative slope: the line falls as you move right.
- Zero slope: a horizontal line with the equation
y = b. - Undefined slope: a vertical line, where both points share the same x value. The equation is
x = a, and no y-intercept exists unless the line is the y-axis itself.
The angle of inclination is arctan(m), measured from the positive x-axis, so a slope of 1 is 45 degrees. The grade is simply the slope times 100, the form used for roads, ramps and railways. A grade of 8% means 8 units of rise for every 100 units of horizontal run.
Parallel and perpendicular lines
Two non-vertical lines are parallel when their slopes are equal. They are perpendicular when the product of their slopes is −1, so the perpendicular slope is the negative reciprocal −1 ÷ m. A line with slope 3 is perpendicular to one with slope −1/3. The special cases are a horizontal line, whose perpendicular is vertical with an undefined slope, and a vertical line, whose perpendicular is horizontal with slope 0.
The point-slope form y − y1 = m(x − x1) is often the quickest way to write a line when you already know one point and the slope. To find the distance between your two points as well, the result panel includes it; the distance calculator explains that formula in detail.
Common mistakes
- Subtracting in mixed order. Using y2 − y1 on top but x1 − x2 on the bottom flips the sign. Keep the same order in both.
- Dropping negative signs. Subtracting a negative coordinate adds, so 7 − (−5) is 12, not 2.
- Treating a vertical line as slope zero. A vertical line has an undefined slope. A horizontal line has slope zero.
- Different units on the axes. If x is in metres and y is in centimetres, the slope carries those mixed units. Convert first when you want a pure ratio.
- Reading the angle on a stretched graph. The angle here assumes both axes use the same scale. A plot with unequal scales makes lines look steeper or flatter than the computed angle.
Worked example
A line passes through (−2, 7) and (4, −5). Find its slope and equation.
Inputs
| Point 1: x1 | -2 |
|---|---|
| Point 1: y1 | 7 |
| Point 2: x2 | 4 |
| Point 2: y2 | -5 |
Result
Falling line (negative slope). Rise -12 over run 6.
| Rise (y2 − y1) | -12 |
|---|---|
| Run (x2 − x1) | 6 |
| Equation (y = mx + b) | y = -2x + 3 |
| y-intercept b | 3 |
| x-intercept | 1.5 |
| Angle of inclination | -63.4349° |
| Grade (slope as a percentage) | -200% |
| Slope of a perpendicular line | 0.5 |
| Distance between the points | 13.4164 |
Accuracy note: Results use standard double-precision arithmetic, so very large or very small values may be rounded. Check important results by another method.
Frequently asked questions
How do I find the slope between two points?
Subtract the y values to get the rise, subtract the x values in the same order to get the run, then divide the rise by the run. For (1, 2) and (5, 10) that is 8 ÷ 4 = 2.
What does an undefined slope mean?
It means the line is vertical, so both points have the same x value and the run is zero. Division by zero is not defined, which is why the calculator reports a vertical line with equation x = a.
Can the slope be a fraction or a decimal?
Yes. Slopes are usually ratios, so values like 1/2 or 0.75 are common. The calculator shows decimals, rounded to four places, and the exact fraction is rise over run.
How is slope different from grade or gradient?
They describe the same ratio. Gradient is another word for slope, and grade is the slope written as a percentage, so a slope of 0.05 is a 5% grade.
How do I find a line perpendicular to my line?
Take the negative reciprocal of the slope. If the slope is 4 the perpendicular slope is −1/4, and if the slope is −2/3 the perpendicular slope is 3/2.
Related calculators
References and sources
- Standard coordinate geometry: slope-intercept and point-slope forms of a straight line, as covered in any secondary-school algebra text.