Algebra
How To Calculate Slope
Slope is how much a quantity changes vertically for one unit of horizontal movement. It turns two data points into a rate, and once you have it, the whole line follows.
Quick Answer
Slope = (y2 - y1) / (x2 - x1)
- m
- Slope — the rate of change of y per unit of x
- y2 - y1
- Rise — how much the vertical coordinate changed
- x2 - x1
- Run — how much the horizontal coordinate changed
- b
- Y-intercept — where the line crosses the vertical axis
Subtract the y values to get the rise, subtract the x values to get the run, then divide. For the points (2, 3) and (8, 15) the rise is 12 and the run is 6, giving a slope of 2. Working backwards with y = mx + b, the intercept is -1, so the line is y = 2x - 1 and any value can be predicted from it. A horizontal line has slope 0 and a vertical line has undefined slope.
What Is Slope?
Slope measures steepness and direction simultaneously, and the two readings are packed into one number. Its magnitude says how fast the quantity changes — a slope of 2 means the vertical value rises two units for every one unit across. Its sign says which way: positive runs uphill from left to right, negative runs downhill, zero is flat, and anything steeper than vertical cannot be expressed this way at all.
The formula divides the change in y by the change in x, which is why students hear "rise over run". What matters practically is that both differences must be taken in the same direction. Subtracting point one from point two in the numerator while doing the reverse in the denominator produces the negative of the correct answer, and there is no warning in the result — it simply describes a line sloping the other way.
One genuinely reassuring property is that the choice of which point is first does not matter, provided you are consistent. Taking point two minus point one in both coordinates gives the same result as point one minus point two, because the minus signs cancel. This invariance is a useful check: computing the slope twice with reversed orders should give identical answers, and if it does not, your subtraction was inconsistent.
Once the slope is known, the rest of the line is one step away. Substituting either point into y = mx + b and solving for b gives the intercept: with m = 2 and the point (2, 3), we get 3 = 2(2) + b, so b = -1 and the line is y = 2x - 1. Everything else follows — the x-intercept from setting y to zero, predictions of y for any x, and the x that corresponds to any target y.
The distance between the two points is a different quantity that people routinely conflate with slope. It comes from the Pythagorean relationship: sqrt((delta x)^2 + (delta y)^2), which here gives sqrt(36 + 144) = 13.4164 units. Two very different questions — how steep versus how far apart — and getting them confused is common when someone needs "how much" without specifying which.
Slope also encodes everyday rates whenever the horizontal axis is time. Distance against time gives speed, cost against units gives unit price, savings against months gives a monthly rate. In each case the slope is a rate with units: kilometres per hour, dollars per item, dollars per month. Reading slope as "units of y per one unit of x" converts an abstract number into something you can act on.
Parallel and perpendicular lines are decided entirely by slope, which is why the number is so useful beyond graphing. Parallel lines share the same slope. Perpendicular lines have slopes whose product is -1, so a line of slope 2 meets one of slope -0.5 at right angles. This relationship handles everything from road gradients to making sure a corner is square.
Real measured data nearly always fails to sit on a perfect line, so the practical version is the slope of a best-fit line rather than of any two particular points. That computation uses every point and minimises total squared error, which is why the result is more robust than picking two convenient observations. When your two points are measurements rather than exact values, they belong to this statistical version.
Two situations need care. A vertical line has no defined slope because the run is zero and the division cannot be performed — sometimes described informally as infinite, but mathematically undefined. And a curve has no single slope at all, only a slope at each point, which is precisely the question calculus was built to answer.
Formula
m = (y2 - y1) / (x2 - x1)
Rise divided by run. Take both differences in the same direction, or the sign reverses.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| x1, y1 | Coordinates of the first point | coordinates | Order does not matter as long as both differences are taken the same way. |
| x2, y2 | Coordinates of the second point | coordinates | If x2 equals x1 the line is vertical and the slope is undefined. |
| m | Slope of the line | units of y per unit of x | Positive slopes rise left to right; negative slopes fall. |
b = y1 - m x x1
Rearranged from y = mx + b using either known point. This completes the line equation.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| b | Y-intercept | same as y | The value of y when x is zero, which may or may not be meaningful in context. |
d = sqrt((x2 - x1)^2 + (y2 - y1)^2)
The straight-line separation, from Pythagoras. Related to slope but answering a different question.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| d | Straight-line distance | same as coordinates | Independent of which point you call first, because both differences are squared. |
How To Calculate Slope
- 1
Label the two points consistently
Call one (x1, y1) and the other (x2, y2). Which is which does not matter, but once chosen it must not change partway through the calculation.
- 2
Compute the rise
y2 - y1 = 15 - 3 = 12. Keep the sign — it tells you whether the line rises or falls as you move right.
- 3
Compute the run
x2 - x1 = 8 - 2 = 6. If this comes out zero, stop: the line is vertical and has no defined slope.
- 4
Divide rise by run
12 / 6 = 2. Read it as "y increases 2 units for every 1 unit of x", rather than as an abstract number.
- 5
Find the intercept to complete the line
Substitute either point into y = mx + b: b = 3 - 2 x 2 = -1. The line is y = 2x - 1, which you can verify against the second point.
Examples
Example 1: The line through (2, 3) and (8, 15)
- Point 1
- (2, 3)
- Point 2
- (8, 15)
| Step | Calculation | Result |
|---|---|---|
| Rise | 15 - 3 | 12 |
| Run | 8 - 2 | 6 |
| Slope | 12 ÷ 6 | 2 |
| Intercept from the first point | 3 - 2 x 2 | -1 |
| Verify with the second point | 2 x 8 - 1 | 15 |
Result: Slope 2 with intercept -1, giving y = 2x - 1 — and substituting x = 8 reproduces y = 15 at the second point.
Example 2: Why the order of points does not matter
- Forward
- Point 1 minus Point 2
- Backward
- Point 2 minus Point 1
- Risk
- Mixing the two directions
| Step | Calculation | Result |
|---|---|---|
| Taking point two minus point one | (15 - 3) ÷ (8 - 2) | 12 ÷ 6 = 2 |
| Taking point one minus point two | (3 - 15) ÷ (2 - 8) | -12 ÷ -6 = 2 |
| Mixing directions — the error to avoid | (15 - 3) ÷ (2 - 8) | 12 ÷ -6 = -2 |
| Distance between the same points | sqrt(6^2 + 12^2) | 13.4164 |
Result: 2 whichever order you choose, and -2 only when the subtraction directions are mixed — the slope is invariant, but sloppy is not. The same two points sit 13.4164 units apart.
Example 3: Flat lines, vertical lines and parallel checks
- Horizontal
- (1, 5) to (9, 5)
- Vertical
- (4, 1) to (4, 9)
- Comparison
- (1, 2) to (4, 8)
| Step | Calculation | Result |
|---|---|---|
| Horizontal line | (5 - 5) ÷ (9 - 1) | 0 |
| Vertical line | (9 - 1) ÷ (4 - 4) | not defined — the run is zero |
| A second line with the same steepness | (8 - 2) ÷ (4 - 1) | 2, so parallel to the first example |
| Slope of a perpendicular line | -1 ÷ 2 | -0.5 |
Result: 0 for flat, undefined for vertical, 2 for the parallel line and -0.5 for one meeting it at right angles.
Calculator
Slope of the line
2
- Y-intercept
- -1
- X-intercept
- 0.5
- Distance between the two points
- 13.4164
Values update as you type. This calculator covers the single scenario its formula assumes — see Common Mistakes for what it leaves out.
Prefer a full-width tool? Open the Slope calculator page.
Common Mistakes
Mixing the subtraction order between numerator and denominator
Taking y2 - y1 with x1 - x2 gives the negative of the correct answer. Always move in the same direction through both coordinates.
Confusing slope with distance
Slope answers how steep, distance answers how far. Two points far apart can have a shallow slope, and two close points a steep one.
Assuming all lines have a slope
Vertical lines do not — the run is zero and the division cannot be performed. Saying the slope is infinite is a useful shorthand but mathematically it is undefined.
Using slope on data that curves
A curve has no single slope. Two nearby points give the average rate over that interval, which is only an approximation of the instantaneous rate at either end.
Extrapolating a fitted slope too far beyond the data
Real relationships bend and saturate. A line fitted over observed values says nothing reliable about behaviour far outside that range, however confident the arithmetic looks.
FAQ
What does a negative slope mean?
That the two quantities move in opposite directions: as one increases the other decreases. A slope of -3 means each unit of increase in x corresponds to a fall of three units in y.
Does it matter which point I call the first one?
No, as long as you subtract both coordinates in the same direction. Reversing both changes the sign of both differences, and those signs cancel in the division.
How do I know if two lines are parallel?
Compare slopes. Equal slopes mean parallel lines, and slopes multiplying to -1 mean perpendicular ones. A slope of 2 meets only lines with slope -0.5 at right angles.
What is the difference between slope and gradient?
In ordinary algebra they mean the same thing. In multivariable calculus, gradient refers to a vector of partial derivatives for a surface, which is a generalisation rather than a different concept.
How do I find the slope when my points are measurements?
Use a best-fit line across all points rather than any two, because individual observations carry error. The least-squares method minimises total squared vertical distance and produces a far more stable estimate.
References
- [1]Khan Academy, Slope, intercepts and linear equations — https://www.khanacademy.org/math/algebra/x2f8bb11595b61c86:linear-equations-graphs
- [2]National Institute of Standards and Technology (NIST), Engineering Statistics Handbook, Line slope and linear regression definitions — https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm
- [3]Wolfram MathWorld, Slope, gradient and line geometry — https://mathworld.wolfram.com/Slope.html