Slope and Line Equation Calculator: m and b from Two Points
About this calculator The slope calculator takes two points on a line, ( x 1 , y 1 ) (x_1, y_1) ( x 1 , y 1 ) and ( x 2 , y 2 ) (x_2, y_2) ( x 2 , y 2 ) , and returns the slope m m m and the y y y -intercept b b b —that is, it writes the line in the form y = m x + b y = mx + b y = m x + b .
Slope answers the question “for every increase of 1 in x x x , how much does y y y change?”: how much a ramp rises per 100 m travelled, how many degrees Fahrenheit change per degree Celsius, how much speed increases per second. Whenever two quantities are related by a straight line, measuring two points gives the whole line, and the y y y for any x x x then follows from the equation.
What it does not do: it does not check whether the two points really lie on the same line (any two points determine a line), it does not handle vertical lines (slope undefined), it does not find the intersection of two lines, and it does not fit curves—if three or more points are not collinear, what you need is regression, not this calculator.
How to use this calculator 01 Open the panel this page corresponds to “Math tools → Formulas → Slope / line equation” (/#/mathtools/formula?calculator=calculator.slope). On opening, only x₁ = 1 and y₁ = 2 are pre-filled; enter x₂ and y₂ too (the default example is 4, 8)—the result is meaningful only when all four coordinates are “input”. 02 Enter the two points in either order; swapping the points changes the sign of both Δ y \Delta y Δ y and Δ x \Delta x Δ x , so the slope is unchanged. 03 Read the slope and intercept “Slope m” and “y-intercept b”, marked “computed”, update live to at most 8 decimal places with trailing zeros removed. Substitute them into y = m x + b y = mx + b y = m x + b for the equation of the line. 04 Vertical lines when x 1 = x 2 x_1 = x_2 x 1 = x 2 the slope shows ∞ and so does the intercept—the line is x = x 1 x = x_1 x = x 1 and has no slope-intercept form. 05 Convert to an angle or grade the panel does not output an angle directly; use θ = arctan m \theta = \arctan m θ = arctan m (tan⁻¹ on a scientific calculator), and the grade percentage is m × 100 m \times 100 m × 100 .
Worked examples All four examples were recomputed by the engine’s slope compute routine; the display convention is at most 8 decimal places with trailing zeros removed. Angles are converted separately with arctan m \arctan m arctan m .
Example 1: panel defaults (1, 2) and (4, 8)
Δ x = 4 − 1 = 3 \Delta x = 4 - 1 = 3 Δ x = 4 − 1 = 3 , Δ y = 8 − 2 = 6 \Delta y = 8 - 2 = 6 Δ y = 8 − 2 = 6 .
m = 6 / 3 = 2 m = 6/3 = 2 m = 6/3 = 2 .
b = y 1 − m x 1 = 2 − 2 × 1 = 0 b = y_1 - m x_1 = 2 - 2 \times 1 = 0 b = y 1 − m x 1 = 2 − 2 × 1 = 0 .
Interface shows: slope 2 , y-intercept 0 . The line is y = 2 x y = 2x y = 2 x , through the origin; angle of inclination arctan 2 = 63.43 ° \arctan 2 = 63.43° arctan 2 = 63.43° .
Figure 1: Example 1. Slope is rise over run; the intercept is where the line crosses the y axis
Example 2: a falling line, (2, 5) and (6, 3)
Δ x = 4 \Delta x = 4 Δ x = 4 , Δ y = 3 − 5 = − 2 \Delta y = 3 - 5 = -2 Δ y = 3 − 5 = − 2 .
m = − 2 / 4 = − 0.5 m = -2/4 = -0.5 m = − 2/4 = − 0.5 .
b = 5 − ( − 0.5 ) ( 2 ) = 6 b = 5 - (-0.5)(2) = 6 b = 5 − ( − 0.5 ) ( 2 ) = 6 .
Interface shows: slope −0.5 , y-intercept 6 . Equation y = − 0.5 x + 6 y = -0.5x + 6 y = − 0.5 x + 6 ; angle of inclination arctan ( − 0.5 ) = − 26.57 ° \arctan(-0.5) = -26.57° arctan ( − 0.5 ) = − 26.57° (sloping downward). A line perpendicular to it has slope − 1 / m = 2 -1/m = 2 − 1/ m = 2 .
Example 3: grade and angle
A stretch of road rises 6 m over 100 m of horizontal distance: enter ( 0 , 0 ) (0, 0) ( 0 , 0 ) and ( 100 , 6 ) (100, 6) ( 100 , 6 ) .
Interface shows: slope 0.06 , intercept 0 . Grade = 0.06 × 100 % = 6 % = 0.06 \times 100\% = 6\% = 0.06 × 100% = 6% , angle arctan 0.06 = 3.43 ° \arctan 0.06 = 3.43° arctan 0.06 = 3.43° . Note that a 6% grade is not 6°: grade is tan θ \tan\theta tan θ , the angle is θ \theta θ , and for small angles θ ( rad ) ≈ tan θ \theta(\text{rad}) \approx \tan\theta θ ( rad ) ≈ tan θ , so 6% ≈ 0.06 rad ≈ 3.4°. A “4:12” roof pitch has slope 4 / 12 = 0.333 4/12 = 0.333 4/12 = 0.333 and an angle of 18.43°.
Example 4: a unit conversion is a straight line
Celsius and Fahrenheit: the freezing point of water ( 0 ° C , 32 ° F ) (0\,°\text{C}, 32\,°\text{F}) ( 0 ° C , 32 ° F ) , the boiling point ( 100 ° C , 212 ° F ) (100\,°\text{C}, 212\,°\text{F}) ( 100 ° C , 212 ° F ) .
Interface shows: slope 1.8 , intercept 32 . This gives F = 1.8 C + 32 F = 1.8\,C + 32 F = 1.8 C + 32 —the slope 1.8 °F/°C means “1.8 °F per 1 °C”, and the intercept 32 is the Fahrenheit temperature at 0 °C. Here m m m has units (°F/°C) and cannot be converted to an angle.
Horizontal and vertical lines
Enter ( 1 , 4 ) (1, 4) ( 1 , 4 ) and ( 5 , 4 ) (5, 4) ( 5 , 4 ) : Δ y = 0 \Delta y = 0 Δ y = 0 , slope 0 , intercept 4 , line y = 4 y = 4 y = 4 . Enter ( 3 , 1 ) (3, 1) ( 3 , 1 ) and ( 3 , 7 ) (3, 7) ( 3 , 7 ) : Δ x = 0 \Delta x = 0 Δ x = 0 , the interface shows slope ∞ and intercept ∞ —this is the line x = 3 x = 3 x = 3 , which cannot be written as y = m x + b y = mx + b y = m x + b .
The inputs of Example 1 can be entered directly into the panel to reproduce it; change y₂ to 2 and the slope becomes 0 (a horizontal line).
Principles and derivation Slope is a rate of change
The essence of a straight line is that “y y y changes at a constant rate with x x x ”: whichever two points you measure from, Δ y / Δ x \Delta y / \Delta x Δ y /Δ x is the same. This constant ratio is the slope, and it unifies the geometric notion of “steepness” with the algebraic notion of “change in y y y per unit x x x ”. In physics, the slope of a displacement–time graph is velocity and the slope of a velocity–time graph is acceleration; in economics, the slope of a cost–output line is marginal cost. Calculus extends the idea to curves: the derivative at a point is the slope of the tangent there.
Why two points are enough
Infinitely many lines pass through one point; adding a second point leaves exactly one. Similar triangles show why the slope does not depend on which two points you pick: any two pairs of points on the line form, with the axes, two right triangles that are similar (equal corresponding angles), so “vertical side / horizontal side” is the same for both. This also explains why swapping the points leaves the result unchanged—numerator and denominator change sign together.
Forms of the equation of a line
Form
Equation
When it is convenient
Slope-intercept
y = m x + b y = mx + b y = m x + b
Slope and y y y -intercept known; this calculator’s output
Point-slope
y − y 1 = m ( x − x 1 ) y - y_1 = m(x - x_1) y − y 1 = m ( x − x 1 )
Slope and any one point known
Two-point
y − y 1 y 2 − y 1 = x − x 1 x 2 − x 1 \dfrac{y - y_1}{y_2 - y_1} = \dfrac{x - x_1}{x_2 - x_1} y 2 − y 1 y − y 1 = x 2 − x 1 x − x 1
Only two points known and you do not want to compute m m m first
General
A x + B y + C = 0 Ax + By + C = 0 A x + B y + C = 0
Includes vertical lines (B = 0 B = 0 B = 0 ); slope is − A / B -A/B − A / B
Intercept
x a + y b = 1 \dfrac{x}{a} + \dfrac{y}{b} = 1 a x + b y = 1
Intersections with both axes, ( a , 0 ) (a, 0) ( a , 0 ) and ( 0 , b ) (0, b) ( 0 , b ) , known
Multiplying both sides of the two-point form by ( y 2 − y 1 ) (y_2 - y_1) ( y 2 − y 1 ) and rearranging gives the point-slope form; expanding gives the slope-intercept form with b = y 1 − m x 1 b = y_1 - m x_1 b = y 1 − m x 1 , which is exactly how the engine computes the intercept.
Parallel, perpendicular and the angle between lines
Two non-vertical lines are parallel ⟺ their slopes are equal; perpendicular ⟺ the product of their slopes is − 1 -1 − 1 (m 2 = − 1 / m 1 m_2 = -1/m_1 m 2 = − 1/ m 1 ). The perpendicular result comes from rotating a line by 90°: the original “run Δ x \Delta x Δ x , rise Δ y \Delta y Δ y ” becomes “run − Δ y -\Delta y − Δ y , rise Δ x \Delta x Δ x ”, and the new slope is Δ x / ( − Δ y ) = − 1 / m \Delta x / (-\Delta y) = -1/m Δ x / ( − Δ y ) = − 1/ m . The angle between two lines satisfies tan φ = ∣ m 2 − m 1 1 + m 1 m 2 ∣ \tan\varphi = \left|\dfrac{m_2 - m_1}{1 + m_1 m_2}\right| tan φ = 1 + m 1 m 2 m 2 − m 1 .
Angle, grade and “percent”
m = tan θ m = \tan\theta m = tan θ links slope and angle of inclination. Engineering more often uses the grade percentage m × 100 % m \times 100\% m × 100% : a 6% grade rises 6 m per 100 m, a 45° slope is 100%, and a vertical wall has infinite grade, not 100%. Railways use “per mille” (‰), roofs use “rise in 12” (rise : 12), mountaineers use degrees—all different notations for the same m m m . For small angles tan θ ≈ θ \tan\theta \approx \theta tan θ ≈ θ (in radians), so 6% ≈ 3.4°, not 6°.
Relationship to the distance formula
Δ x \Delta x Δ x and Δ y \Delta y Δ y are the two legs of a right triangle whose hypotenuse is the distance between the points, Δ x 2 + Δ y 2 \sqrt{\Delta x^2 + \Delta y^2} Δ x 2 + Δ y 2 (see the distance calculator ). Slope uses only the ratio of the legs; distance uses the sum of their squares. For the same pair of points, the two calculators read different aspects of the same triangle.
Assumptions
Two points determine a unique line : any two distinct points define a line; the calculator does not check whether they come from the same “real” line (measured data may be noisy, for example).
Cartesian coordinates with linear axes : the coordinates are ordinary Cartesian coordinates; “slope” on logarithmic or polar axes means something different.
x 2 ≠ x 1 x_2 \ne x_1 x 2 = x 1 : two points with the same x x x define a vertical line, whose slope is undefined; the interface shows ∞.
Units follow the axes : the slope’s unit is the y y y unit divided by the x x x unit; it can be converted to an angle only when both axes share a unit.
All four coordinates must be filled in : the panel pre-fills only x₁ and y₁ and treats unfilled coordinates as 0. The default example happens to give the same result as (1, 2)–(4, 8), but in general make all four fields “input”.
Scope and limitations Can calculate the slope and y y y -intercept of the line through any two points (with different x x x ) in Cartesian coordinates; results to at most 8 decimal places. Approximate only when the points come from measurement, the error in the slope is roughly ( ∣ Δ y ∣ ε x + ∣ Δ x ∣ ε y ) / Δ x 2 (|\Delta y|\,\varepsilon_x + |\Delta x|\,\varepsilon_y)/\Delta x^2 ( ∣Δ y ∣ ε x + ∣Δ x ∣ ε y ) /Δ x 2 ; the closer the points, the more the error is amplified. Cannot calculate the equation of a vertical line (written as x = x 1 x = x_1 x = x 1 ), the best-fit line through three or more points (use linear regression), or the slope of a tangent to a curve (use the derivative). Does not output the angle or grade percentage (convert by hand), find the x x x -intercept (− b / m -b/m − b / m ), test collinearity, or convert units. Numerics when the points are extremely close, Δ x \Delta x Δ x approaches 0 and floating-point error is amplified, so the result may contain large numerical noise.
Common mistakes
Inconsistent order in numerator and denominator : m = ( y 2 − y 1 ) / ( x 2 − x 1 ) m = (y_2 - y_1)/(x_2 - x_1) m = ( y 2 − y 1 ) / ( x 2 − x 1 ) ; the subscripts in both differences must be in the same order. Writing ( y 2 − y 1 ) / ( x 1 − x 2 ) (y_2 - y_1)/(x_1 - x_2) ( y 2 − y 1 ) / ( x 1 − x 2 ) flips the sign.
Putting Δ x \Delta x Δ x in the numerator : slope is rise over run, not run over rise; the latter is the reciprocal of the slope.
Treating a grade percentage as an angle : 6% means tan θ = 0.06 \tan\theta = 0.06 tan θ = 0.06 , i.e. 3.4°; a 100% grade is 45°, not 90°.
Forgetting to substitute a point for the intercept : b b b is not y 1 y_1 y 1 but y 1 − m x 1 y_1 - m x_1 y 1 − m x 1 ; the two agree only when x 1 = 0 x_1 = 0 x 1 = 0 .
Reading ∞ for a vertical line and still using slope-intercept form : the line x = 3 x = 3 x = 3 has no y = m x + b y = mx + b y = m x + b form; ∞ is a signal, not a usable number.
Filling in only the first two coordinates : the panel pre-fills only x₁ and y₁ and treats the other two as 0; enter x₂ and y₂ as well.
Talking about angles on axes with different units : the “1.8” on a Celsius–Fahrenheit graph is °F/°C, not tan 61 ° \tan 61° tan 61° .
Typical use cases Teaching: from two points to an equation Start with (1, 2) and (4, 8) to get y = 2 x y = 2x y = 2 x , then change y₂ to 5, 2 and −1 to watch the slope go from positive through zero to negative; change x₂ to 1 to see ∞ appear—a direct demonstration that “a vertical line has no slope”.
Roads, ramps and roofs Measure the horizontal distance and the rise (same unit), enter (0, 0) and (run, rise); the slope times 100 is the grade percentage, and arctan \arctan arctan gives the angle. An accessibility ramp of 1:12 corresponds to slope 0.0833, grade 8.3%, angle 4.76°.
Calibrating a linear relationship Enter two calibration points (the freezing and boiling points of two temperature scales, two calibration readings from a sensor) to obtain the conversion formula y = m x + b y = mx + b y = m x + b ; any later reading can be substituted directly. When the intercept is 0 it reduces to a simple proportional relationship .
Slopes of physics graphs Take two points on a velocity–time graph and the slope is the acceleration; the slope of a displacement–time graph is velocity; the slope of a resistor’s U U U –I I I graph is its resistance. Any two points on the graph will do, but the further apart they are, the smaller the error.
FAQ What does a negative slope mean? y y y decreases as x x x increases; the line slopes from upper left to lower right. The larger the absolute value of the slope, the steeper the line.
Why does the slope show ∞? The two points have the same x x x coordinate, Δ x = 0 \Delta x = 0 Δ x = 0 , and the division is undefined. The line is the vertical line x = x 1 x = x_1 x = x 1 ; it has no slope-intercept equation and no y y y -intercept (unless it is the y y y axis itself).
How do I get the angle of inclination? θ = arctan m \theta = \arctan m θ = arctan m . A slope of 2 corresponds to 63.43°, a slope of 1 to 45°, a slope of 0.06 to 3.43°. This has geometric meaning only when both axes share a unit.
How do I find the x-intercept? Set y = 0 y = 0 y = 0 : x = − b / m x = -b/m x = − b / m . In Example 2, x = − 6 / ( − 0.5 ) = 12 x = -6/(-0.5) = 12 x = − 6/ ( − 0.5 ) = 12 .
How do I test whether three points are collinear? Compute the slope for any two pairs of points; if they are equal the points are collinear (allowing a small discrepancy for floating-point error). For three or more non-collinear points, use linear regression to find the “closest” line—this calculator does not do that.
Is the result reliable when the two points are very close? Not very. When Δ x \Delta x Δ x is tiny, small errors in the coordinates are amplified by the division and the slope can be far off. Choose two points as far apart as possible.
References and further reading
The slope definition in the CalcX engine source src/data/formulas.ts (m = ( y 2 − y 1 ) / ( x 2 − x 1 ) m = (y_2-y_1)/(x_2-x_1) m = ( y 2 − y 1 ) / ( x 2 − x 1 ) , b = y 1 − m x 1 b = y_1 - m x_1 b = y 1 − m x 1 ); every figure on this page was recomputed by that engine, with angles converted via arctan m \arctan m arctan m .
Wikipedia, Slope (访问日期:2026-09-08)—definition, angle of inclination, parallel and perpendicular lines, relationship to the derivative.
Wikipedia, Linear equation (访问日期:2026-09-08)—the various forms of the equation of a line.
Wikipedia, Grade (slope) (访问日期:2026-09-08)—conversion between grade percentage, ratio and angle.
Stewart, J. Calculus: Early Transcendentals , 8th ed. Cengage, 2016. Appendix B, “Coordinate Geometry and Lines”—standard derivations of slope, line equations and the parallel/perpendicular conditions.
Privacy All inputs and calculations run inside your browser and are never uploaded to a server. The text on this page is static content; it neither contains nor records any user input.
Sources & review
Reviewed by CalcX 编辑组
Updated 2026-09-09
Open Slope and Line Equation Calculator: m and b from Two Points in CalcX