Skip to content
thecalculatorstudio

Slope Calculator: Slope of a Line Between Two Points

Enter two points. You get the slope, the angle the line makes with the x-axis, the grade in percent, the equation of the line, the distance and the midpoint.

Last reviewed

Slope m

2

rise 6 over run 3, so the line is rising

Line
y = 2x
Angle to the x-axis
63.43494882°
Grade
200%
Distance between the points
6.7082039325
Midpoint
(2.5, 5)

Slope is the rise (change in y) divided by the run (change in x). It equals the tangent of the angle the line makes with the x-axis.

What slope is

The slope of a line says how steeply it climbs or falls. Wolfram MathWorld defines it as the change in the vertical coordinate over the change in the horizontal one, m = Δy/Δx, and notes that for a line making an angle θ with the x-axis it is a constant, equal to tan θ. Most people know it as rise over run.

For two points (x₁, y₁) and (x₂, y₂):

m = (y₂ − y₁) ÷ (x₂ − x₁)

  • A positive slope rises to the right.
  • A negative slope falls to the right.
  • A zero slope is a horizontal line.
  • A vertical line has an undefined slope, since the run is zero.

The line, the angle and the grade

Once you have the slope you can describe the line in three more ways:

  • Equation. MathWorld gives the slope-intercept form y = mx + b. The intercept is b = y₁ − m × x₁.
  • Angle. θ = atan(m), the inverse tangent, in degrees.
  • Grade. The slope times 100, as a percentage. A road with a 6% grade rises 6 metres for every 100 metres along the ground.

The calculator also gives the distance between the points, √(Δx² + Δy²), and the midpoint, the average of the coordinates.

Worked examples

(1, 2) and (4, 8). Δy = 8 − 2 = 6 and Δx = 4 − 1 = 3, so m = 2. Then b = 2 − 2 × 1 = 0, giving the line y = 2x. The angle is atan(2) = 63.4349°, the grade is 200%, the distance is √45 = 6.7082 and the midpoint is (2.5, 5).

(3, 7) and (5, 1). Δy = −6 and Δx = 2, so m = −3. Then b = 7 − (−3)(3) = 16, so the line is y = −3x + 16, falling to the right at an angle of −71.5651°. The distance is √40 = 6.3246.

(−2, −1) and (3, 4). Δy = 5 and Δx = 5, so m = 1, the line is y = x + 1, and the angle is exactly 45°.

(0, 3) and (5, 3). Δy = 0, so m = 0 and the line is y = 3.

(2, 1) and (2, 9). Δx = 0, so the slope is undefined and the line is x = 2.

Slope, angle and grade side by side

Slope Angle Grade
0.05 2.8624° 5%
0.25 14.0362° 25%
0.5 26.5651° 50%
1 45° 100%
2 63.4349° 200%
5 78.6901° 500%

A grade over 100% is steeper than 45°, which is why a 100% grade does not mean a vertical wall.

Common mistakes

  • Subtracting in different orders. Subtract both coordinates in the same order. Swapping the points changes both signs, so the slope is the same.
  • Dividing run by rise. That gives the reciprocal.
  • Reading a negative slope as a mistake. It means the line falls to the right.
  • Treating percent grade as degrees. A 10% grade is 5.71°, not 10°.
  • Dividing by zero. A vertical line has no slope.

To work with the triangle under the line, use the right triangle calculator, and for the distance alone the distance calculator.

Gradients in the real world

  • A road sign of 10% is a slope of 0.1, an angle of 5.7106°.
  • A wheelchair ramp at the common limit of 1 in 12 has a slope of 0.0833, which is a grade of 8.33% and an angle of 4.7636°. A ramp that rises 0.5 m therefore needs a run of 6 m.
  • A roof pitch of 6 in 12 has a slope of 0.5, which is 26.565°.

Building rules set the allowed slope for ramps, stairs and drains, so use the figure in the rules that apply to your job, not just the one above.

How it is calculated

All of the arithmetic is exact decimal arithmetic to 50 digits, and results are shown to 12 significant figures, with the angle to 10. Angles use the inverse tangent.

Frequently asked questions

What is the slope formula?

Slope m = (y₂ − y₁) ÷ (x₂ − x₁), the change in y divided by the change in x, often called rise over run. MathWorld writes it as m = Δy/Δx, and it equals the tangent of the angle the line makes with the x-axis.

What is the slope of a vertical line?

It is undefined, because the run is zero and you cannot divide by zero. A vertical line has the equation x = a, and the calculator says so instead of showing a number.

What is the slope of a horizontal line?

Zero. The rise is zero however far you run, so the line is y = b, where b is the height of the line.

How do I turn a slope into an angle?

Take the inverse tangent: θ = atan(m). A slope of 1 is 45°, a slope of 2 is 63.43°, and a negative slope gives a negative angle for a line falling to the right.

What is grade in percent?

The slope times 100. A grade of 5% rises 5 units for every 100 units of run. The same slope as an angle is smaller than people expect: 100% is 45°, and 5% is only about 2.86°.

How do I write the equation of the line?

Use y = mx + b. Find m from the two points, then b = y₁ − m × x₁. For the points (1, 2) and (4, 8), m = 2 and b = 0, so the line is y = 2x.

Related calculators

Sources