Algebra
Quadratic Formula
The five-term solution that always works for ax² + bx + c = 0
The quadratic formula gives the exact solutions to any equation of the form ax² + bx + c = 0, where a ≠ 0. The two roots are x = (−b ± √(b² − 4ac)) / 2a. Memorized by every algebra student, derived from completing the square, and the source of the discriminant b² − 4ac that tells you how many real solutions exist before you compute them.
- Formulax = (−b ± √(b² − 4ac)) / 2a
- DiscriminantΔ = b² − 4ac
- Discriminant > 0Two distinct real roots
- Discriminant = 0One real root (repeated)
- Discriminant < 0Two complex roots (conjugate pair)
- DerivationComplete the square on ax² + bx + c
Interactive visualization
Press play, or step through manually. The visualization is yours to drive — try it before reading on.
Watch the 60-second explainer
A condensed visual walkthrough — narrated, captioned, under a minute.
The formula
For any quadratic equation ax² + bx + c = 0 with a ≠ 0, the solutions are:
x = (−b ± √(b² − 4ac)) / 2a
The ± gives two solutions — one with +, one with −. The expression under the square root, b² − 4ac, is called the discriminant and tells you what kind of solutions to expect before computing them.
The discriminant — three cases
| Discriminant Δ = b² − 4ac | Number of real roots | Geometric meaning |
|---|---|---|
| Δ > 0 | Two distinct real roots | Parabola crosses the x-axis at two points |
| Δ = 0 | One real root (repeated) | Parabola touches the x-axis at exactly one point (vertex) |
| Δ < 0 | Zero real roots; two complex conjugate roots | Parabola doesn't touch the x-axis |
The complex roots in the Δ < 0 case have the form (−b ± i√|Δ|) / 2a. They come in conjugate pairs because the original coefficients are real.
Derivation by completing the square
Start with the general quadratic:
ax² + bx + c = 0
Step 1 — divide by a (we can because a ≠ 0):
x² + (b/a)x + c/a = 0
Step 2 — move c/a to the right:
x² + (b/a)x = −c/a
Step 3 — complete the square. Add (b/2a)² to both sides:
x² + (b/a)x + (b/2a)² = (b/2a)² − c/a
Step 4 — factor the left side as a perfect square:
(x + b/2a)² = (b² − 4ac) / (4a²)
Step 5 — take square roots and solve:
x + b/2a = ± √(b² − 4ac) / (2a)
x = (−b ± √(b² − 4ac)) / (2a)
That's the formula, derived in five lines. The square root in step 5 is what produces the ±, and what creates the discriminant inside.
Worked examples
Example 1 — two real roots
Solve x² − 5x + 6 = 0. Here a = 1, b = −5, c = 6.
Δ = (−5)² − 4·1·6 = 25 − 24 = 1
x = (5 ± √1) / 2 = (5 ± 1) / 2
x = 3 or x = 2
Verify by factoring — x² − 5x + 6 = (x − 2)(x − 3). ✓
Example 2 — repeated root
Solve 4x² − 12x + 9 = 0. Here a = 4, b = −12, c = 9.
Δ = (−12)² − 4·4·9 = 144 − 144 = 0
x = 12 / (2·4) = 3/2
One repeated root. Verify — 4x² − 12x + 9 = (2x − 3)².
Example 3 — complex roots
Solve x² + x + 1 = 0. Here a = 1, b = 1, c = 1.
Δ = 1 − 4 = −3
x = (−1 ± √(−3)) / 2 = (−1 ± i√3) / 2
Two complex conjugate roots. These are the non-real cube roots of 1 (besides 1 itself).
Vieta's formulas — sum and product of roots
If r₁ and r₂ are the roots of ax² + bx + c = 0, then:
r₁ + r₂ = −b/a
r₁ · r₂ = c/a
You can verify by adding/multiplying the formula's two output values. These let you construct a quadratic with desired roots — if you want roots 3 and 5, take a = 1, then b = −(3+5) = −8 and c = 3×5 = 15. The quadratic is x² − 8x + 15.
JavaScript: numerically stable solver
function quadratic(a, b, c) {
if (a === 0) {
if (b === 0) return c === 0 ? 'infinite solutions' : 'no solution';
return [-c / b]; // linear case
}
const disc = b * b - 4 * a * c;
if (disc > 0) {
// Stable formula — avoid catastrophic cancellation
const sqrtD = Math.sqrt(disc);
// Pick the larger-magnitude term in numerator
const q = -0.5 * (b + Math.sign(b) * sqrtD);
return [q / a, c / q];
} else if (disc === 0) {
return [-b / (2 * a)];
} else {
// Complex roots
const real = -b / (2 * a);
const imag = Math.sqrt(-disc) / (2 * a);
return [{ re: real, im: imag }, { re: real, im: -imag }];
}
}
quadratic(1, -5, 6); // [3, 2]
quadratic(4, -12, 9); // [1.5]
quadratic(1, 1, 1); // [{re: -0.5, im: 0.866...}, {re: -0.5, im: -0.866...}]
The "stable" form handles cases like a = 1, b = -10⁸, c = 1, where the naive formula loses ~7 digits of precision. Vieta's relation r₁ × r₂ = c/a lets us compute the smaller root by division instead of subtraction.
Python implementation
import cmath
def quadratic(a, b, c):
"""Returns roots of ax² + bx + c = 0 as a tuple."""
if a == 0:
return () if b == 0 else (-c / b,)
disc = b*b - 4*a*c
sqrtD = cmath.sqrt(disc)
return ((-b + sqrtD) / (2*a), (-b - sqrtD) / (2*a))
quadratic(1, -5, 6) # ((3+0j), (2+0j))
quadratic(1, 1, 1) # ((-0.5+0.866j), (-0.5-0.866j))
Python's cmath module handles complex arithmetic natively. cmath.sqrt(-3) returns 1.732j instead of throwing.
Quadratic formula vs other methods
| Method | When to use | Advantages | Drawbacks |
|---|---|---|---|
| Quadratic formula | Always (when you need exact roots) | Always works; gives both roots; reveals discriminant | Tedious for "easy" cases |
| Factoring | Integer or simple rational roots | Fast; reveals structure | Can't factor when roots aren't rational |
| Completing the square | Want vertex form for graphing | Gives vertex (h, k) directly | More steps than the formula |
| Graphical / numerical | Don't need exact answer | Visual intuition; works for any function | Approximate |
When the formula doesn't apply
- a = 0. The equation isn't quadratic; it's linear. The formula's denominator is zero. Solve as bx + c = 0.
- Higher-degree polynomials. ax³ + bx² + cx + d = 0 needs the cubic formula or numerical methods. The "quadratic formula" is specifically for degree 2.
- Non-polynomial equations. e^x = sin(x), x² + 2^x = 5 — transcendental equations have no algebraic formula. Use numerical root-finding (Newton's method, bisection).
- Equations in multiple variables. x² + y² = 1 (a circle, not a single quadratic). The formula solves for one variable at a time, treating others as parameters.
Common mistakes
- Sign errors on b. The formula has −b, not +b.
x² − 5x + 6 = 0has b = −5, so −b = +5 — easy to drop a sign. - Forgetting to divide everything by 2a. The denominator applies to the whole numerator, not just one term. Brackets matter.
- Computing the discriminant wrong. b² − 4ac, not (b−4ac)² or b·b − 4·a·c (those are the same; the issue is operator precedence in pen-and-paper).
- Square-rooting a negative without going to complex. When discriminant is negative, the answers are complex. Some calculators just say "ERROR"; you need to switch to complex mode or use cmath.
- Catastrophic cancellation in floating-point. When b² is much larger than 4ac, the naive formula loses precision. Use the numerically stable form (Vieta's relation) for production code.
- Confusing roots with x-intercepts. If a quadratic has complex roots (Δ < 0), there are no x-intercepts on the real plane — the parabola never touches the x-axis. The complex roots aren't visible on a real-number graph.
Frequently asked questions
How do you derive the quadratic formula?
Start with ax² + bx + c = 0. Divide by a. Move c/a to the right. Complete the square — add (b/2a)² to both sides. Factor the left as a perfect square. Take square roots. Solve for x. Five steps and you've derived the formula. The formula isn't magic; it's the result of completing the square on the general quadratic.
What does the discriminant tell you?
b² − 4ac decides what kind of roots the equation has. Positive → two distinct real roots (parabola crosses x-axis twice). Zero → one repeated real root (parabola touches x-axis at exactly one point). Negative → two complex conjugate roots, no real solutions (parabola doesn't touch x-axis). You can answer "does this quadratic have real solutions?" by checking the discriminant without computing the roots.
Why do we always say a ≠ 0?
If a = 0, the equation isn't quadratic — it's linear (bx + c = 0). The formula's denominator becomes zero, undefined. The whole technique only applies to genuine quadratics; if a is small but nonzero, you can use it but should verify numerical stability.
What if the equation isn't in standard form?
Rearrange first. <code>3x² = 2x + 8</code> becomes <code>3x² − 2x − 8 = 0</code> with a = 3, b = −2, c = −8. The formula needs the standard form ax² + bx + c = 0; algebraic manipulation gets you there.
Are there formulas for cubics and higher?
Cubics — yes, Cardano's formula (16th century, complicated, requires complex numbers even for real-rooted cases). Quartics — yes, Ferrari's formula (also 16th century, even more complicated). Quintics and higher — no, by the Abel-Ruffini theorem (1824). General degree ≥ 5 polynomials have roots that can't always be expressed in radicals. Numerical methods (Newton's, Durand-Kerner) handle them.
When does the quadratic formula give floating-point errors?
When b² ≫ 4ac, computing −b + √(b² − 4ac) loses precision (catastrophic cancellation between two nearly equal numbers). Numerically stable approach — compute the larger root with the formula, then use the fact that x₁ × x₂ = c/a to compute the smaller root by division. Saves several decimal places of precision.
What's the relationship between roots and coefficients (Vieta's formulas)?
For ax² + bx + c = 0 with roots r₁ and r₂ — sum r₁ + r₂ = −b/a, product r₁r₂ = c/a. So you can construct a quadratic with desired roots: if you want roots 3 and 5, pick a = 1, b = −(3+5) = −8, c = 3×5 = 15 — the polynomial x² − 8x + 15 = (x−3)(x−5). Vieta's formulas extend to higher-degree polynomials and let you read off properties of roots from coefficients.