Quadratic equation solver

Solve ax² + bx + c = 0 with the quadratic formula: exact roots as surds or complex numbers, the discriminant, vertex and axis of symmetry, and a graph.

Drafted with AI writing toolsUpdated Checked examples: 7

Try
Roots
x = 2 ± √3
Roots: x = 2 ± √3
Smaller root x₁
0.2679491924
Larger root x₂
3.7320508076
Discriminant b² − 4ac
12
Kind of roots
Two distinct real roots
Vertex x (axis of symmetry)
2
Vertex y (minimum or maximum)
−3

The discriminant is positive (12), so the parabola crosses the x-axis twice: x = 2 ± √3. It opens upward with a minimum of −3 at x = 2.

y = x² − 4x + 1

-2.502.55024xyaxis x = 2vertex (2, −3)x₁x₂
How it's calculated S
  1. Discriminant

    Δ=b2−4ac=(−4)2−4(1)(1)=12\Delta = b^2 - 4ac = (-4)^2 - 4(1)(1) = 12
  2. Quadratic formula

    x=−b±Δ2a=4±122x = \frac{-b \pm \sqrt{\Delta}}{2a} = \frac{4 \pm \sqrt{12}}{2}
  3. Simplify the square root

    12=23\sqrt{12} = 2\sqrt{3}
  4. Roots

    x=2±3  ⇒  x1≈0.267949192431, x2≈3.73205080757x = 2 \pm \sqrt{3} \;\Rightarrow\; x_1 \approx 0.267949192431,\ x_2 \approx 3.73205080757
  5. Vertex

    h=−b2a=2,k=c−b24a=−3h = -\frac{b}{2a} = 2,\qquad k = c - \frac{b^2}{4a} = -3

About the quadratic equation solver

A quadratic equation ax² + bx + c = 0, with a ≠ 0, has the roots x = (−b ± √(b² − 4ac)) / 2a. The discriminant Δ = b² − 4ac decides their kind: two real roots when Δ > 0, one repeated root when Δ = 0, and a pair of complex conjugates when Δ < 0. The vertex of the parabola y = ax² + bx + c sits on its axis of symmetry, x = −b/2a.

Projectile heights, areas with one unknown side and break-even points all lead to quadratics. The default, x² − 4x + 1 = 0, has Δ = 12, so its roots are x = 2 ± √3, about 0.2679 and 3.7321, and its vertex is (2, −3).

Roots are given exactly, as fractions, simplified surds or complex numbers, and as decimals to 10 places. The decimals use the cancellation-free form from Numerical Recipes, so a tiny root next to a large one keeps its accuracy. With a = 0 the equation is linear, not quadratic.

Quadratic equations with fractions or a negative leading coefficient

Multiply every coefficient by the same nonzero number and the roots stay the same, so clear fractions and make the x² coefficient positive before using the quadratic formula. Doubling x²/2 − 3x/2 + 1 = 0 gives x² − 3x + 2 = 0, with roots 1 and 2.

Changing every sign flips the parabola but keeps the roots. Multiplying −x² + 2x + 1 = 0 by −1 gives x² − 2x − 1 = 0. Both have roots 1 ± √2, but the first parabola peaks at (1, 2) and the second bottoms out at (1, −2).

The discriminant b² − 4ac scales by the square of the multiplier, so its sign, and with it the kind of roots, never changes: doubling x²/2 − 3x/2 + 1 turns Δ = 1/4 into 4 × 1/4 = 1.

The table gives the discriminant of each equation as written, before any scaling:

abcDiscriminantKind of roots
1-4112Two distinct real roots
23-549Two distinct real roots
125−16Two complex conjugate roots
1-690One repeated real root
3-21−8Two complex conjugate roots
-1218Two distinct real roots
1/2-3/211/4Two distinct real roots
13-40169Two distinct real roots

For the complex row 3x² − 2x + 1, Δ = 4 − 12 = −8, so the roots are (1 ± i√2)/3, about 0.3333 ± 0.4714i.

How to solve a quadratic equation with the quadratic formula

For any equation ax² + bx + c = 0 with a ≠ 0, the solutions are x = (−b ± √(b² − 4ac)) / 2a. For 2x² − 7x + 3 = 0, a = 2, b = −7 and c = 3, so x = (7 ± √25)/4 = (7 ± 5)/4, giving x = 3 or x = 1/2.

The same five steps work on every quadratic:

  1. Move every term to one side so the equation reads ax² + bx + c = 0, and copy a, b and c with their signs.
  2. Work out the discriminant, Δ = b² − 4ac.
  3. Take its square root. A negative Δ has no real square root, so the roots are a complex pair.
  4. Evaluate (−b + √Δ)/2a and (−b − √Δ)/2a.
  5. Check a root by substituting it: 2 × 3² − 7 × 3 + 3 = 18 − 21 + 3 = 0.

What the discriminant tells you

For whole-number or fractional coefficients, the discriminant sorts every quadratic into one of four cases.

Discriminant ΔRootsGraph of y = ax² + bx + cExampleΔRoots of the example
Positive perfect squareTwo rational rootsCrosses the x-axis twice3x² − 5x − 249−1/3 and 2
Positive, not a perfect squareTwo irrational roots, a ± √ pairCrosses the x-axis twicex² + 6x + 420−3 ± √5
ZeroOne repeated rootTouches the x-axis at the vertex4x² − 12x + 903/2
NegativeTwo complex conjugate rootsStays on one side of the x-axisx² − 4x + 13−362 ± 3i

Check the first row before reaching for the formula: a perfect-square discriminant means the quadratic factors over the integers or fractions. With decimal coefficients from measurements that case is rare, and the formula is the practical route.

Worked example: a garden with a known area

A rectangular garden is 3 m longer than it is wide and covers 40 m². Calling the width w, the area gives w(w + 3) = 40, and in standard form w² + 3w − 40 = 0, so a = 1, b = 3 and c = −40.

  1. Discriminant: Δ = 3² − 4 × 1 × (−40) = 9 + 160 = 169.
  2. Square root: √169 = 13, a whole number, so the roots are rational.
  3. Formula: w = (−3 ± 13)/2, giving w = 10/2 = 5 or w = −16/2 = −8.
  4. Interpret: a width cannot be negative, so the garden is 5 m wide and 8 m long. Check: 5 × 8 = 40.

Both roots solve the equation. Which one to discard depends on the problem, not the algebra.

Worked example: when does a thrown ball land?

A ball thrown upward at 14 m/s from a height of 1.5 m, taking g as 9.8 m/s², is at height h = −4.9t² + 14t + 1.5 meters after t seconds. Setting h = 0 gives Δ = 14² − 4 × (−4.9) × 1.5 = 225.4.

The roots simplify to (10 ± √115)/7, about −0.1034 and 2.9605. The negative time lies before the throw, so the ball lands after 2.96 s.

The vertex, at t = 1.4286 and h = 11.5, is the top of the flight: the ball peaks at 11.5 m after 1.43 s.

Where the quadratic formula comes from

The formula is what you get by completing the square on ax² + bx + c = 0 once, with letters instead of numbers:

  1. Divide by a, which is allowed because a ≠ 0: x² + (b/a)x + c/a = 0.
  2. Move the constant across: x² + (b/a)x = −c/a.
  3. Add (b/2a)² to both sides, which turns the left side into a perfect square: (x + b/2a)² = (b² − 4ac)/4a².
  4. Take the square root of both sides, keeping both signs: x + b/2a = ±√(b² − 4ac)/2a.
  5. Subtract b/2a: x = (−b ± √(b² − 4ac))/2a.

Step 4 is where the discriminant enters. The right side of step 3 has a positive denominator, 4a², so the sign of b² − 4ac alone decides whether a real square root exists.

Factoring and completing the square

When the discriminant is a perfect square, factoring is often quicker than the formula. The ac method handles a leading coefficient other than 1. For 6x² + x − 2 = 0:

  1. Multiply a and c: 6 × (−2) = −12.
  2. Find two numbers with product −12 and sum b = 1: 4 and −3.
  3. Split the middle term with them: 6x² + 4x − 3x − 2.
  4. Factor in pairs: 2x(3x + 2) − 1(3x + 2) = (2x − 1)(3x + 2).
  5. Set each factor to zero: x = 1/2 or x = −2/3.

Completing the square works on any quadratic and is quickest when a = 1 and b is even. For x² + 6x − 7 = 0, move the constant to get x² + 6x = 7, then add (6/2)² = 9 to both sides.

That gives (x + 3)² = 16, so x + 3 = ±4 and x = 1 or x = −7. It is the derivation above, applied to numbers.

Vertex form and the axis of symmetry

Completing the square without setting the expression to zero rewrites y = ax² + bx + c in vertex form, y = a(x − h)² + k, where h = −b/2a and k = c − b²/4a. For y = 2x² − 8x + 3:

  • h = −(−8)/(2 × 2) = 2
  • k = 3 − (−8)²/(4 × 2) = 3 − 8 = −5
  • so y = 2(x − 2)² − 5, which expands back to 2x² − 8x + 3.

The vertex is (2, −5). Because a = 2 is positive, the parabola opens upward, −5 is its minimum, and the axis of symmetry is the line x = 2.

Setting y = 0 gives 2(x − 2)² = 5, so x = 2 ± √(5/2), also written (4 ± √10)/2: about 0.4189 and 3.5811. Both sit 1.5811 either side of the axis, as every pair of real roots does.

Two quick checks catch most arithmetic slips: the roots add up to −b/a and multiply to c/a. Here 0.4189 + 3.5811 = 4 = 8/2 and 0.4189 × 3.5811 = 1.5 = 3/2.

To see the parabola alongside other curves, plot it in the graphing calculator.

Mistakes and edge cases

  • Leaving the equation out of standard form. x² = 3x + 4 must become x² − 3x − 4 = 0 before reading off a, b and c; its roots are −1 and 4. Reading b as +3 from the original gives the wrong pair.
  • Losing the sign of b. When b is negative, −b is positive: for 2x² − 8x + 3, −b = 8. And b² is never negative: (−8)² = 64. Typing -8^2 gives −64, because the minus applies after the power, so bracket it as (-8)^2 in the scientific calculator.
  • Dividing only part of the numerator by 2a. The whole of −b ± √Δ sits over 2a. Writing −b ± √Δ/2a divides only the root by 2a.
  • Setting a to 0. Without an x² term the equation is linear, bx + c = 0, with the single root −c/b when b ≠ 0.
  • Rounding a tiny root next to a large one. For x² + 100000000x + 1 = 0 the roots are about −100000000 and −0.00000001. Evaluating −b + √Δ in double-precision arithmetic subtracts two nearly equal numbers, and the small root comes out as −7.45 × 10⁻⁹, 25% too small.

David Goldberg's survey of floating-point arithmetic (ACM Computing Surveys, 1991) explains that cancellation and the rearranged formula that avoids it.

This solver uses the rearrangement with 50-digit decimals, so its small root, −1.0000000000000001 × 10⁻⁸, is correct to every digit shown.

Complex roots, such as 2 ± 3i above, can be carried into further arithmetic with the complex number calculator. For cubic to sixth-degree equations, the polynomial root finder returns every real and complex root.

Worked examples

x² − 4x + 1 (irrational roots)

a (x² coefficient)
1
b (x coefficient)
-4
c (constant)
1
Roots
x = 2 ± √3
Smaller root x₁
0.2679491924
Larger root x₂
3.7320508076
Discriminant b² − 4ac
12
Vertex y (minimum or maximum)
-3

Checked against: Independent calculation

2x² + 3x − 5 (rational roots)

a (x² coefficient)
2
b (x coefficient)
3
c (constant)
-5
Roots
x₁ = −5/2, x₂ = 1
Smaller root x₁
-2.5
Larger root x₂
1
Discriminant b² − 4ac
49

Checked against: Δ = 9 + 40 = 49, (−3 ± 7)/4

x² + 2x + 5 (complex roots)

a (x² coefficient)
1
b (x coefficient)
2
c (constant)
5
Roots
x = −1 ± 2i
Real part (complex roots)
-1
Imaginary part (±)
2
Kind of roots
Two complex conjugate roots

Checked against: Independent calculation

x² − 6x + 9 (double root, edge case)

a (x² coefficient)
1
b (x coefficient)
-6
c (constant)
9
Roots
x = 3 (double root)
Smaller root x₁
3
Larger root x₂
3
Discriminant b² − 4ac
0
Kind of roots
One repeated real root

Checked against: (x − 3)² expanded by hand

Questions

What is the quadratic formula?

x = (−b ± √(b² − 4ac)) / 2a gives both solutions of ax² + bx + c = 0. For 2x² + 3x − 5 = 0, a = 2, b = 3 and c = −5, so x = (−3 ± √49)/4 = (−3 ± 7)/4, giving x = 1 and x = −5/2. The formula comes from completing the square and works for every quadratic with a ≠ 0.

What does the discriminant tell you?

The discriminant b² − 4ac counts the real roots. Positive means two different real roots (x² − 4x + 1 has Δ = 12); zero means one repeated root where the parabola touches the x-axis (x² − 6x + 9 has Δ = 0 and root 3); negative means two complex roots (x² + 2x + 5 has Δ = −16). With whole-number coefficients, a perfect-square discriminant such as 49 means the roots are rational.

How do you find the vertex of a parabola?

The vertex x-coordinate is −b/2a; substituting it back gives the y-coordinate, which equals c − b²/4a. For y = x² − 4x + 1 the vertex is at x = 4/2 = 2 and y = 1 − 16/4 = −3. If a > 0 the parabola opens upward and the vertex is its minimum; if a < 0 it opens downward and the vertex is its maximum.

What are complex roots of a quadratic?

When b² − 4ac is negative the square root in the formula is imaginary, so the roots take the form p ± qi, where i = √−1. For x² + 2x + 5 = 0, Δ = 4 − 20 = −16 and √−16 = 4i, so x = (−2 ± 4i)/2 = −1 ± 2i. The parabola never crosses the x-axis, and the real part, −1, is the x-coordinate of its vertex.

Can you solve a quadratic by factoring instead?

Yes, when the roots are rational. x² − 6x + 9 factors as (x − 3)², so x = 3 twice, and 2x² + 3x − 5 factors as (2x + 5)(x − 1), giving −5/2 and 1. x² − 4x + 1 does not factor over whole numbers because its discriminant, 12, is not a perfect square, so the formula's answer 2 ± √3 is needed.

About this calculator

x=−b±b2−4ac2aV=(−b2a, c−b24a)\begin{gathered} x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} \\[10pt] V = \left(-\frac{b}{2a},\ c - \frac{b^2}{4a}\right) \end{gathered}

Sources

  1. Wolfram MathWorld — Quadratic Equation
  2. Press et al., Numerical Recipes (3rd ed.) §5.6 — cancellation-free quadratic roots

Checked against references

This calculator includes 7 worked examples with independently sourced answers. They run in the test suite, and you can run them here too.

Put this calculator on your site

Paste this where you want the calculator to appear. It is free to use, it stays in step with corrections made here, and the credit line below it links back so your readers can find the full version.

Height
Preview the embed

Keep the credit line. It is the only condition, and it is what keeps these calculators free.