Slope Calculator

Calculate the slope (gradient) of a line through two points. Also returns distance, midpoint, and the line equation in y = mx + b form.

How this works

The slope of a line measures how steeply it rises or falls — the change in y for each unit change in x. Given two points (x₁, y₁) and (x₂, y₂), slope is the rise (y₂ − y₁) divided by the run (x₂ − x₁). A positive slope rises left-to-right; a negative slope falls; zero is flat (horizontal); an undefined slope (when x₁ = x₂) is a vertical line. Slope is the same concept whether you call it "rise over run" in algebra class, "gradient" in physics, or "rate of change" in calculus — it always answers "how fast is y changing as x increases?".

In practice, slope shows up everywhere. Engineers spec a road grade as a percent slope (a 6% grade is slope 0.06). Roofers describe pitch as rise per 12 inches of run. Statisticians fit a regression line and report its slope as the coefficient on x. In economics, the slope of a demand curve is how price changes per unit of quantity. The math is identical; only the units and interpretation differ.

This calculator returns four things at once: slope, distance between the points (Pythagorean theorem applied to dx and dy), midpoint, and the line equation in y = mx + b form (with b found by solving y₁ = mx₁ + b for b). Vertical lines are flagged separately since they have no slope-intercept form — the equation is just x = constant.

The formula

slope (m) = (y₂ − y₁) / (x₂ − x₁) distance = √((x₂ − x₁)² + (y₂ − y₁)²) midpoint = ((x₁ + x₂)/2, (y₁ + y₂)/2) y-intercept (b) = y₁ − m·x₁ line equation: y = mx + b

(x₁, y₁) and (x₂, y₂) are the two points. m is the slope. b is the y-intercept (the y-value where the line crosses the y-axis). When x₂ = x₁ the slope is undefined and the line is vertical.

Example calculation

  • Find the slope through (1, 2) and (4, 8).
  • Slope = (8 − 2) / (4 − 1) = 6 / 3 = 2.
  • Distance = √(3² + 6²) = √45 ≈ 6.71. Midpoint = (2.5, 5). Line equation: b = 2 − 2·1 = 0, so y = 2x.

Frequently asked questions

What does a negative slope mean?

The line falls from left to right — y decreases as x increases. A slope of −2 means y drops by 2 units for every 1-unit increase in x. Mirror image of a positive slope.

Why is the slope undefined for vertical lines?

A vertical line has the same x-coordinate at every point, so x₂ − x₁ = 0, and the slope formula divides by zero. Geometrically, "rise over zero run" is infinite — the line goes straight up with no horizontal change. Vertical lines are written as x = constant rather than y = mx + b.

How does slope relate to angle?

Slope equals tan(θ) where θ is the angle the line makes with the horizontal. So a 45° line has slope 1; a 30° line has slope ≈ 0.577; a 60° line has slope ≈ 1.732. To convert a slope to an angle: θ = arctan(slope). Useful for ramps, roof pitches, and any "what angle does this make?" question.

Related calculators