Slope & Line Equation Calculator (y = mx + b from Two Points)
Enter any two points P₁(x₁, y₁) and P₂(x₂, y₂) in the Cartesian plane and instantly read off the slope m, y-intercept b, slope-intercept equation y = mx + b, the Euclidean distance between them, and the midpoint. A four-field tool that covers the everyday coordinate-geometry needs of secondary-school algebra through first-year university. Vertical lines (x₁ = x₂) are auto-rendered as x = c with the slope flagged as undefined.
Enter four real numbers (x₁, y₁, x₂, y₂) — every field must be a finite number.
Line equation
y = 2x
Slope m
2
y-intercept b
0
Distance |P₁P₂|
6.708
Midpoint M
(2.5, 5)
m = (y₂−y₁)/(x₂−x₁) and b = y₁ − m·x₁ together give y = mx + b. Values are rounded to 4 decimals for display only; the underlying computation stays exact.
Formula
m = (y₂ − y₁) / (x₂ − x₁); b = y₁ − m·x₁; line: y = m·x + b; distance = √((x₂−x₁)² + (y₂−y₁)²); midpoint = ((x₁+x₂)/2, (y₁+y₂)/2)
- · Slope m measures rise over run: how many units of y per unit of x. m > 0 rises, m < 0 falls, m = 0 is horizontal. (Stewart, Calculus: Early Transcendentals, Appendix B)
- · The y-intercept b is the y-coordinate where the line meets the y-axis (i.e. y when x = 0); it is recovered as b = y₁ − m·x₁.
- · When x₁ = x₂ the two points share an x-coordinate, the line is vertical and slope is undefined — the tool renders the equation as x = c instead of returning NaN.
- · When y₁ = y₂ the line is horizontal, slope = 0 and the equation simplifies to y = b.
- · The distance formula is the Pythagorean theorem applied to the right triangle whose legs are Δx and Δy and whose hypotenuse joins the two points.
- · The midpoint M is the component-wise arithmetic mean of the two points — equivalently, half of P₁ + P₂ as vectors.
- · Displayed values are rounded to 4 decimals; the underlying numeric computation is unrounded, and the URL preserves your original inputs so a copied link reproduces the result exactly.
- · If both points coincide they do not determine a unique line; the widget says so explicitly rather than dividing 0/0.
Frequently asked
Two points are (1, 2) and (4, 8). What is the equation of the line through them?
Slope first: m = (y₂ − y₁) / (x₂ − x₁) = (8 − 2) / (4 − 1) = 6 / 3 = 2. Then the y-intercept b = y₁ − m·x₁ = 2 − 2·1 = 0. So the line is y = 2x. Plug x₁ = 1, y₁ = 2, x₂ = 4, y₂ = 8 into the tool and you will see slope 2, intercept 0, distance √45 ≈ 6.708 and midpoint (2.5, 5) at the same time.
Why is the slope said to be "undefined" when both points share the same x-coordinate (e.g. (3, 1) and (3, 7))?
The slope formula m = Δy / Δx becomes 0 in the denominator when Δx = 0, which is undefined over the reals (and "infinity" is not a real number). Geometrically the line is perfectly vertical — every point with x = 3 lies on it — so it cannot be written as y = mx + b at all. It must be expressed as x = 3 instead. The tool detects Δx = 0 and renders the equation as "x = c", with the slope field labelled "undefined".
What is the difference between slope-intercept form and point-slope form, and when should I use each?
Slope-intercept y = m·x + b uses the slope m and the y-intercept b — handy for sketching (you read the y-axis crossing directly) and for comparing two lines. Point-slope y − y₁ = m(x − x₁) uses one known point and the slope — most natural for "passes through (x₁, y₁) with slope m" problems and is the intermediate form when deriving an equation from two points. The general form Ax + By + C = 0 is useful for vertical lines and symmetric manipulations. This tool gives you slope-intercept directly (or x = c for vertical lines); to write the point-slope form, just substitute the displayed m and either of your input points.
How does the distance formula √((x₂−x₁)² + (y₂−y₁)²) come from the Pythagorean theorem?
Connect P₁(x₁, y₁) and P₂(x₂, y₂) and treat the segment as the hypotenuse of a right triangle. The horizontal leg has length |x₂ − x₁| and the vertical leg has length |y₂ − y₁|. Pythagoras says leg² + leg² = hypotenuse², so the hypotenuse equals √((x₂−x₁)² + (y₂−y₁)²) — exactly the distance formula. The tool reports this alongside the slope so you can immediately see both the length of the segment and how steep the line is.
A line has slope m = 3 and passes through (2, 7). What are its y-intercept and equation?
Use b = y₁ − m·x₁ = 7 − 3·2 = 1, so the line is y = 3x + 1. If you only know one point and the slope (rather than two points), generate a second point by stepping one unit along x with the slope: from (2, 7) with m = 3 you reach (3, 10). Plug both points into the widget and you will get the same slope, intercept and equation.
Related tools
Percentage Calculator
Percent of, percent change, and percent add/subtract in one.
GCD & LCM Calculator
Enter 2–6 positive integers to get the greatest common divisor (HCF / GCD) and least common multiple (LCM), with the Euclidean step chain shown.
Average Calculator (Mean / Median / Mode)
Enter a list of numbers to get the mean, median, mode, range plus standard deviation, variance and total.
Quadratic Equation Solver
Enter the coefficients of ax² + bx + c = 0 to find the real or complex roots, discriminant and vertex.
Password Strength (Entropy) Calculator
Estimate a password's bit entropy, brute-force time and strength tier. All computation happens in your browser.
Scientific Notation Converter
Convert between standard decimal numbers and scientific notation, with significant figures and order of magnitude.
Permutations & Combinations (nPr / nCr) Calculator
Compute permutations P(n,r), combinations C(n,r) and factorial n! — useful for probability problems, lottery odds and combinatorics homework.
Standard Deviation Calculator
Paste a list of numbers to compute mean, median, sample and population variance and standard deviation — with the working shown.
Triangle Calculator (SSS / SAS / ASA)
Solve a triangle from 3 sides, 2 sides + 1 angle, or 2 angles + 1 side — area, perimeter and remaining parts via the law of sines / cosines.
Pythagorean Theorem Calculator
Given any two sides of a right triangle (two legs, or one leg plus the hypotenuse), instantly find the third side, area, perimeter and the two non-right angles.
Circle Calculator (radius / diameter / circumference / area)
Enter any one of radius, diameter, circumference or area to get the other three — useful for design, engineering and DIY.
Roman Numeral Converter
Two-way conversion between Arabic numbers (1–3999) and Roman numerals (I, V, X, L, C, D, M) — handy for typesetting, chapter titles and homework.
Birthday Paradox Calculator
Enter group size n to see the probability that at least two people share a birthday — the classic birthday problem.
Logarithm Calculator (log / ln / log₂ / any base)
Compute logₐ(x) for any base — natural log (ln), common log (log₁₀), binary log (log₂) and a custom base, with the change-of-base steps shown.
Z-Score (Standard Score) Calculator
Enter a value, the mean and the standard deviation to compute the z-score and the corresponding normal-distribution percentile and probabilities.
Screen Pixel Density (PPI) Calculator
Enter the screen resolution and diagonal size to get pixel density (PPI), real width/height, dot pitch and total pixel count.
Hong Kong Mark Six Odds Calculator
Enter the number of tickets / selections and see the actual probability of hitting first, second … prizes in a Mark Six (6-of-49) draw.
Decimal to Fraction Converter
Convert any decimal (including repeating decimals) to a simplified fraction and a mixed number.
Sphere Volume & Surface Area Calculator
Give a sphere any one of radius, diameter, surface area or volume and instantly get the other three — plus the great-circle circumference and area.
Cylinder Volume & Surface Area Calculator
Enter the radius and height of a cylinder to get volume (π r²h), lateral surface, base area and total surface area.
Prime Factorization Calculator
Factor any integer from 2 up to 10¹² into primes, see the canonical exponent form, count and list all divisors.
Geometric Mean Calculator
Compute the n-th root of the product of n positive numbers — the right average for growth rates, returns and ratios — alongside the arithmetic mean for comparison.
Fibonacci Sequence Calculator
Enter any integer n from 0 to 1500 to instantly compute F(n) and F(n−1) with BigInt precision, the consecutive-term ratio (converging to the golden ratio φ) and the first 30 terms of the sequence.