Slope Calculator
Calculate the slope of a line through two points (x1, y1) and (x2, y2) using slope = (y2 - y1) / (x2 - x1). Handles vertical lines with an explicit undefined-slope result.
How It's Calculated
Formula
m = \frac{y_2 - y_1}{x_2 - x_1}Slope measures how steep a line is: how much y changes for every unit that x changes. Given two points on a line, (x1, y1) and (x2, y2), the slope m is the ratio of the vertical change to the horizontal change between them — rise over run. A positive slope means the line rises from left to right; a negative slope means it falls from left to right; a slope of zero means the line is perfectly horizontal (y never changes). Enter the coordinates of any two points on the line and this calculator computes m = (y2 - y1) / (x2 - x1) directly. One case has no numeric answer: when both points share the same x-coordinate, the line is vertical, and slope is undefined rather than being reported as an extremely large number.
Worked Examples
Standard case: (0, 0) to (4, 8)
- Find the change in y: y2 - y1 = 8 - 0 = 8
- Find the change in x: x2 - x1 = 4 - 0 = 4
- Divide: m = 8 / 4 = 2
- Result: slope = 2 (a positive slope — the line rises 2 units for every 1 unit it runs right)
Vertical line: (3, -1) to (3, 10)
- Find the change in x: x2 - x1 = 3 - 3 = 0
- Since the change in x is 0, the slope formula would require dividing by zero
- Division by zero has no numeric result, so the slope is undefined — not an infinitely large number
- Result: Undefined (vertical line)
Frequently Asked Questions
Why is the slope of a vertical line undefined instead of infinite?
Slope is rise over run — the change in y divided by the change in x. On a vertical line, every point shares the same x-coordinate, so the change in x is exactly zero. Division by zero has no defined numeric result in ordinary arithmetic, so mathematicians call the slope 'undefined' rather than assigning it a value like infinity. This calculator reflects that directly: entering two points with the same x-coordinate returns an explicit 'Undefined (vertical line)' result instead of a number.
What does a slope of zero mean?
A slope of zero means the line is perfectly horizontal — y stays exactly the same no matter how x changes. This happens whenever the two points share the same y-coordinate (and different x-coordinates, so the line isn't also vertical).
Does it matter which point I enter as (x1, y1) versus (x2, y2)?
No. Swapping the two points flips the sign of both the numerator and the denominator in the slope formula, and those two sign flips cancel out, so the slope comes out identical either way. For example, (0,0)-to-(4,8) and (4,8)-to-(0,0) both give a slope of 2.
What's the difference between a positive and a negative slope?
A positive slope means the line rises as you move from left to right — y increases as x increases. A negative slope means the line falls as you move from left to right — y decreases as x increases. The steeper the line, the larger the absolute value of the slope.
Can I use decimal or negative coordinates?
Yes. All four coordinate fields accept decimals and negative numbers, and the formula works exactly the same way regardless of sign — the change in y and the change in x are computed by simple subtraction before dividing.