Slope of a Line Calculator

Enter the coordinates of two points and this calculator returns the slope of the line through them, the rise and run it came from, the angle of inclination in degrees or radians, the percent grade a civil engineer would quote, the slope of any line perpendicular to it, and the equation of the line in slope-intercept form. Vertical lines are reported as having an undefined slope rather than a huge number, because that is what the mathematics says. A conversion table shows the same steepness written as a ratio, a percentage, an angle and a 1-in-N figure.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
x₁The x-coordinate of the first point.1
y₁The y-coordinate of the first point.2
x₂The x-coordinate of the second point.5
y₂The y-coordinate of the second point.10
Report the angle inDegrees for construction and surveying; radians for calculus and code.Degrees

It returns

  • Slope m — Rise divided by run; undefined for a vertical line.
  • Rise (Δy)
  • Run (Δx)
  • Angle of inclination — Measured from the positive x-axis, anticlockwise.
  • Percent grade — The slope multiplied by 100, as used on road signs.
  • Perpendicular slope — The negative reciprocal, −1/m.
  • Equation of the line

The formula

m=y2y1x2x1
θ=arctanm
m2=1m1

In plain text: m = (y₂ − y₁) / (x₂ − x₁) = rise / run

  • mSlope: the change in y for each unit change in x (dimensionless)
  • riseVertical change, y₂ − y₁ (coordinate units)
  • runHorizontal change, x₂ − x₁ (coordinate units)

Both differences must be taken in the same order. Reversing the points flips the sign of the numerator and the denominator together, leaving the slope unchanged.

Updated Category Coordinate Geometry, Lines & Coordinate Systems Verified against published test cases Reading time 10 min

Slope is a rate, not a distance

The slope of a line answers one question: how much does y change for each unit that x increases? A slope of 2 means the line climbs two units for every one it moves right. A slope of −0.5 means it drops half a unit for each unit right. The formula m = (y₂ − y₁)/(x₂ − x₁) is exactly that rate, computed from any two points on the line.

Because a straight line has the same steepness everywhere, the two points you pick do not matter. Choose the pair furthest apart if you are reading them off a graph, since the differences are then large relative to your reading error. And take both differences in the same order: subtracting y in one direction and x in the other flips the sign and turns an uphill into a downhill.

Slope is dimensionless when both axes carry the same unit, which is why it can be quoted as a bare ratio, a percentage or an angle without changing anything physical. When the axes carry different units, slope carries units too — the slope of a distance-time graph is a speed in metres per second, and the slope of a cost-quantity graph is a price per unit.

Ratio, percentage, angle and 1-in-N

The same steepness gets written four different ways depending on the trade, and confusing them is expensive. The slope itself is the pure ratio rise/run. Percent grade is that ratio multiplied by 100, so a slope of 0.08 is an 8% grade — this is the form on highway warning signs. The angle of inclination is arctan(m), which is what a digital level or an inclinometer reads. The 1-in-N form inverts the magnitude: a slope of 1/12 is written 1 in 12, the form used in accessibility and drainage codes.

The crucial point is that percent grade and angle are not the same number and are not even proportional. A 100% grade is 45°, not 90°, because grade is 100 tan θ and the tangent runs away to infinity as the angle nears a right angle. A 10% grade is 5.71° and a 2% grade is 1.15°, so the two numbers never coincide anywhere except at zero — even on the gentlest ground the grade is about 1.75 times the angle in degrees. What is true on gentle ground is that the relationship is very nearly linear: because arctan m stays within 2% of m itself for any slope up to 0.25, percent grade is close to 1.745 times the angle in degrees over the whole range a road or a ramp ever uses. A 4.76° ramp is 1.745 × 4.76 = 8.31%, against the exact 8.33%.

Steepness thresholds in real codes are quoted in whichever form is easiest to check on site. The 2010 ADA Standards for Accessible Design cap a new ramp's running slope at 1:12, which is 8.33% or 4.76°. Highway signs post grades in percent because a driver's stopping distance depends on the ratio, not the angle. Roofers use a rise-in-12 pitch because that is what a framing square measures directly.

Worked example: the slope from (1, 2) to (5, 10)

Work the default points by hand, then convert the answer into every form a trade might want.

  1. Find the rise. y₂ − y₁ = 10 − 2 = 8.
  2. Find the run. x₂ − x₁ = 5 − 1 = 4.
  3. Divide. m = 8 ÷ 4 = 2. The line climbs two units for every one across.
  4. Convert to percent grade. 2 × 100 = 200%. Steeper than any road.
  5. Convert to an angle. arctan(2) = 63.434949°. Note that 200% is nowhere near 200 degrees.
  6. Find the perpendicular slope. −1 ÷ 2 = −0.5, so any line at right angles to this one falls half a unit per unit across.
  7. Write the equation. b = y₁ − mx₁ = 2 − 2(1) = 0, so the line is y = 2x.

Check it by testing the second point: 2 × 5 = 10, which matches y₂, so the equation is right. Reverse the point order as a second check: rise = 2 − 10 = −8 and run = 1 − 5 = −4, and −8 ÷ −4 = 2 again. The slope does not depend on which point you call first.

Now a practical one. A ramp rises 1 foot over a 12-foot run: m = 1/12 = 0.083333, grade 8.3333%, angle arctan(0.083333) = 4.763642°. That is the steepest ramp the ADA permits on a new build, and the reason the code states it as 1:12 is that a builder can verify a 1-in-12 ratio with a level and a tape without any trigonometry at all.

Sign, magnitude and the two special cases

Read the sign first. A positive slope rises left to right; a negative slope falls left to right. A slope of zero is a horizontal line. The sign is a statement about direction only, and it flips if you flip the orientation of the axes — which is why screen coordinates, where y increases downwards, make a positive slope look like it is falling.

Read the magnitude second. A magnitude below 1 means the line runs further than it rises, so it is shallower than 45°. A magnitude above 1 means it rises faster than it runs, so it is steeper than 45°. Exactly 1 is the 45-degree diagonal in both directions.

Two cases need care. A horizontal line has slope 0, a perfectly ordinary number, and its perpendicular is vertical, which has no slope at all — that is why the perpendicular field shows a dash for a horizontal input. A vertical line has zero run, so the slope is undefined rather than infinite; it cannot be written in y = mx + b form at all and is instead written x = constant. This calculator reports 90° for its angle of inclination and 0 for its perpendicular slope, both of which are well defined even where the slope is not.

Slope, percent grade and angle side by side

Each angle is arctan(m) evaluated at the slope in the first column, and each grade is 100m. The 1-in-N column is 1 divided by the slope.
Slope mPercent gradeAngle1 in NWhere you meet it
0.020832.08%1.19°1 in 48Maximum cross slope on an accessible route
0.055%2.86°1 in 20Steeper than this and a walking surface counts as a ramp (ADA 403.3)
0.083338.33%4.76°1 in 12Maximum ADA ramp running slope
0.1010%5.71°1 in 10A steep highway grade
0.2525%14.04°1 in 4A 3-in-12 roof pitch
0.5050%26.57°1 in 2A 6-in-12 roof pitch
1.00100%45.00°1 in 1A 12-in-12 roof pitch
2.00200%63.43°2 in 1Far steeper than any road or roof

The gap between grade and angle widens as the slope grows: at 5% they differ by a factor of 1.75, at 100% by a factor of 2.22. Never treat a percent grade as an angle.

Errors that flip or inflate a slope

  • Subtracting in inconsistent orders. (y₂ − y₁) over (x₁ − x₂) reverses the sign. Keep both subtractions pointing the same way.
  • Inverting to run over rise. Slope is rise over run. Using run over rise gives the reciprocal, which is the cotangent of the angle rather than its tangent.
  • Reading a percent grade as an angle. A 100% grade is 45 degrees. The two coincide only near zero, where arctan(m) ≈ m in radians.
  • Calling a vertical slope infinite. Division by zero is undefined, not infinite. A vertical line has no slope and no y = mx + b form; write x = constant instead.
  • Taking the perpendicular as −m rather than −1/m. The product of two perpendicular slopes is −1, so the perpendicular of 2 is −0.5, not −2.

The 1:12 ramp rule

Section 405.2 of the 2010 ADA Standards for Accessible Design limits the running slope of a new ramp to 1:12, which is a slope of 0.0833, a grade of 8.33%, or an angle of 4.76°. Section 405.3 limits the cross slope to 1:48, or 2.08%. The code states both as ratios rather than angles because a ratio is directly measurable on site with a spirit level and a tape, with no trigonometry involved. Always check the edition in force in your jurisdiction, since state and local amendments are common.

Where slope leads next

Slope is the bridge between geometry and calculus. The slope of a straight line is constant; the slope of a curve changes from point to point, and the derivative is exactly the limiting slope of the line through two points as they close together. Everything you do with rise over run here reappears there as dy/dx.

In coordinate geometry, slope is the test for parallel and perpendicular. Two lines are parallel when their slopes are equal, and perpendicular when the product of their slopes is −1. Combined with a point, a slope determines a whole line, which is what the line equation calculator produces and what the line intersection calculator consumes.

For the other properties of the same pair of points, use the distance formula calculator for the segment's length and the midpoint calculator for its centre; together with the perpendicular slope from this page, those two give you the perpendicular bisector. To turn a slope back into an angle in a different unit, the inverse trig functions calculator and the degrees to radians calculator handle the conversion.

Frequently asked questions

What is the slope formula?

m = (y₂ − y₁) ÷ (x₂ − x₁), often remembered as rise over run. Subtract the y-coordinates for the rise, subtract the x-coordinates in the same order for the run, and divide. From (1,2) to (5,10) the rise is 8, the run is 4, and the slope is 2.

How do I convert a slope to an angle?

Take the arctangent: θ = arctan(m). A slope of 1 gives 45°, a slope of 0.5 gives 26.57°, and a slope of 2 gives 63.43°. Going the other way, m = tan θ. Be careful not to confuse this with percent grade, which is simply 100m and is a different number entirely.

Is a 100% grade the same as a 90-degree slope?

No. A 100% grade means the road rises one unit for every one it runs forward, which is a 45-degree angle. Percent grade is 100 × tan(angle), so it grows without bound as the angle approaches 90°: an 80-degree slope is a 567% grade. The two figures only track each other closely below about 10%.

Why is the slope of a vertical line undefined?

Because the run is zero and division by zero has no result. A vertical line changes y without changing x at all, so there is no finite rate of change of y with respect to x. It is not infinite — it simply does not exist. Vertical lines are written x = constant rather than y = mx + b.

What is the slope of a line perpendicular to mine?

The negative reciprocal, −1/m. If your slope is 2, the perpendicular slope is −0.5; if yours is −3/4, the perpendicular is 4/3. The product of two perpendicular slopes is always −1. The exceptions are horizontal and vertical lines: the perpendicular of a horizontal line is vertical, whose slope is undefined.

Does it matter which point I call first?

No. Reversing the points flips the sign of both the rise and the run, and a negative divided by a negative is positive, so the slope is unchanged. What does matter is consistency: if you subtract y in one order you must subtract x in the same order, or the sign comes out backwards.

What slope is allowed for a wheelchair ramp?

A maximum of 1:12 running slope for a new ramp under the 2010 ADA Standards for Accessible Design, which is a slope of 0.0833, a grade of 8.33%, or an angle of 4.76°. The cross slope is limited to 1:48, or 2.08%. Local codes may be stricter, so check the standard in force where you are building.

How do I find the equation of the line from two points?

Compute the slope m, then find the intercept from b = y₁ − mx₁ and write y = mx + b. For (1,2) and (5,10), m = 2 and b = 2 − 2 = 0, so the line is y = 2x. This calculator reports that equation directly, and the line equation calculator gives you the other standard forms as well.

References

  • 2010 ADA Standards for Accessible Design, sections 405.2 and 405.3U.S. Department of Justice
  • A Policy on Geometric Design of Highways and Streets (the Green Book), 7th ed. — American Association of State Highway and Transportation Officials
  • Precalculus: Mathematics for Calculus, 7th ed. — Cengage (Stewart, Redlin, Watson)