What is the slope of a line?
Enter two points to get the slope of the line through them, its equation, and its angle. Or enter the slope to find a missing coordinate.
- Slope (m)
- 1.5
The line through (1, 2) and (5, 8) has a slope of 1.5.
- Equation of the line
- y = 1.5x + 0.5
- y-intercept (b)
- 0.5
- Angle of incline
- 56.309932°
- Grade
- 150%
- Rise (Δy)
- 6
- Run (Δx)
- 4
- Distance between the points
- 7.211103
Slope (m): 1.5. The line through (1, 2) and (5, 8) has a slope of 1.5.
Where are the points?
How to calculate
Finds the slope of the line through two points, with its angle, distance, y-intercept and equation, or a missing coordinate from the slope.
Example with the default inputs (x₁ 1, y₁ 2, x₂ 5, y₂ 8): The line through (1, 2) and (5, 8) has a slope of 1.5.
Formula: m = (y₂ − y₁) ÷ (x₂ − x₁): the rise between two points divided by the run.
- The two points must have different x-coordinates: a vertical line has no slope.
- The angle is arctan m, measured from the positive x-axis, between −90° and 90°.
- Coordinates are plain numbers from −10¹⁰⁰ to 10¹⁰⁰, in one unit; a coordinate worked out beyond that has no answer.
Worked examples
Each example is checked against the calculator on every build.
- x₁ 1, y₁ 2, x₂ 5, y₂ 8 gives Slope (m) 1.5, y-intercept (b) 0.5, Equation of the line y = 1.5x + 0.5, Angle of incline 56.309932°, Grade 150%, Rise (Δy) 6, Run (Δx) 4, Distance between the points 7.211103.Source: hand calculation in content.mdx: m = (8 − 2) ÷ (5 − 1) = 1.5; Python 3: math.atan(1.5) = 0.982793723247329, math.hypot(4, 6) = 7.211102550927978
- x₁ -2, y₁ 3, x₂ 4, y₂ -9 gives Slope (m) -2, y-intercept (b) -1, Equation of the line y = -2x - 1, Distance between the points 13.416408.Source: hand calculation in content.mdx: m = −12 ÷ 6 = −2, b = 3 − (−2)(−2) = −1; Python 3: math.hypot(6, 12) = 13.416407864998739
- x₁ 0, y₁ 4, x₂ 7, y₂ 4 gives Slope (m) 0, Equation of the line y = 4, Angle of incline 0°, Grade 0%.Source: hand calculation in content.mdx: a horizontal line has rise 0, so m = 0
- x₁ 2, y₁ 1, x₂ 10, Slope (m) 0.75 gives y₂ 7, y-intercept (b) -0.5.Source: hand calculation in content.mdx: y₂ = 1 + 0.75 × (10 − 2) = 7
- x₁ 1, y₁ 1, y₂ 4, Slope (m) 1 gives x₂ 4, Equation of the line y = x, Angle of incline 45°.Source: hand calculation in content.mdx: x₂ = 1 + (4 − 1) ÷ 1 = 4; arctan 1 = 45°
How it works
The slope m of the line through the points (x₁, y₁) and (x₂, y₂) is the rise divided by the run:
m = (y₂ − y₁) ÷ (x₂ − x₁)
Fill in any four of x₁, y₁, x₂, y₂ and m, and the calculator finds the fifth:
- Slope: m = (y₂ − y₁) ÷ (x₂ − x₁)
- y₂ = y₁ + m × (x₂ − x₁), and y₁ = y₂ − m × (x₂ − x₁)
- x₂ = x₁ + (y₂ − y₁) ÷ m, and x₁ = x₂ − (y₂ − y₁) ÷ m (these need a slope other than 0)
Once all five are known it also shows:
- Rise Δy = y₂ − y₁ and run Δx = x₂ − x₁
- y-intercept b = y₁ − m × x₁, where the line crosses the y-axis. A result smaller than 10⁻¹² of the larger of y₁ and m × x₁ is rounding left over from decimals such as 0.1, and is shown as 0.
- Equation of the line in slope-intercept form, y = mx + b. Its numbers are shown as elsewhere on the page: at most 6 decimal places (6 significant figures below 0.0001), with thousands separators, and a plain hyphen for a minus sign. A slope that shows as 1 is written as x, one that shows as −1 as −x, and one that shows as 0 leaves just y = b.
- Angle of incline = arctan m, the angle from the positive x-axis, shown in degrees (between −90° and 90°)
- Grade = m × 100%
- Distance between the points = √(Δx² + Δy²)
Assumptions
- The two points must have different x-coordinates. When x₁ = x₂ the line is vertical and has no slope, so there is no answer.
- A missing x-coordinate needs a slope other than 0: on a horizontal line every x fits.
- Coordinates are plain numbers from −10¹⁰⁰ to 10¹⁰⁰, all in one unit. A coordinate worked out beyond that range has no answer.
- Two points with the same x and different y make a vertical line: the page gives no slope and says, for x = 1: "The line is vertical (x = 1), so its slope is undefined."
Worked examples by hand
Through (1, 2) and (5, 8). The rise is 8 − 2 = 6 and the run is 5 − 1 = 4, so m = 6 ÷ 4 = 1.5 and the grade is 150%. b = 2 − 1.5 × 1 = 0.5, so the line is y = 1.5x + 0.5. The angle is arctan 1.5 = 56.31° (0.9828 radians), and the distance is √(4² + 6²) = √52 = 7.211103.
Through (−2, 3) and (4, −9). m = (−9 − 3) ÷ (4 − (−2)) = −12 ÷ 6 = −2. b = 3 − (−2)(−2) = −1, so the line is y = −2x − 1. The distance is √(6² + 12²) = √180 = 13.416408.
Through (0, 4) and (7, 4). The rise is 0, so m = 0, the angle is 0°, the grade 0%, and the line is y = 4.
From (2, 1) with slope 0.75, where x₂ = 10. y₂ = 1 + 0.75 × (10 − 2) = 1 + 6 = 7. b = 1 − 0.75 × 2 = −0.5.
From (1, 1) with slope 1, where y₂ = 4. x₂ = 1 + (4 − 1) ÷ 1 = 4. b = 1 − 1 = 0, so the line is y = x, at an angle of arctan 1 = 45°.
Other questions people ask
How do I find the slope between two points?
Subtract the y-coordinates, subtract the x-coordinates in the same order, and divide: m = (y₂ − y₁) ÷ (x₂ − x₁). Through (1, 2) and (5, 8), the rise is 8 − 2 = 6 and the run is 5 − 1 = 4, so the slope is 6 ÷ 4 = 1.5.
What does the slope tell me?
How steep the line is and which way it goes. A slope of 1.5 means y goes up 1.5 for every 1 that x goes right. A positive slope rises from left to right, a negative slope falls, and a slope of 0 is a flat, horizontal line.
What is the slope of a vertical line?
It has none (it is undefined). On a vertical line the run x₂ − x₁ is 0, and you cannot divide by 0. Its equation is x = a number, such as x = 3, rather than y = mx + b.
How do I get the equation of the line from two points?
Find the slope m, then the y-intercept b = y₁ − m × x₁, and write y = mx + b. Through (1, 2) and (5, 8): m = 1.5 and b = 2 − 1.5 × 1 = 0.5, so the line is y = 1.5x + 0.5.
How do I turn a slope into an angle or a percent grade?
The angle is the arctangent of the slope: arctan 1.5 = 56.31°. The grade is the slope times 100: a slope of 0.08 is an 8% grade, as on road signs. A slope of 1 is a 45° angle and a 100% grade.
Does it matter which point I call the first?
No. Swapping the points changes the sign of both the rise and the run, so their quotient, the slope, stays the same. Only keep the same order for x and y: (y₂ − y₁) ÷ (x₂ − x₁).