Chemistry

pH Calculator

Calculate the pH of strong and weak acids and bases from concentration and pKa, using the exact charge balance rather than shortcuts that fail in dilute solutions.

Real Larzscript running in your browser847 automated checksOpen source · MITNo sign-up · your inputs never leave your device

Choose the solution

Total amount dissolved per litre
Ignored for strong acids and bases
pH
—
pOH
—
[H⁺] mol/L
—
[OH⁻] mol/L
—
Percent ionised
—

pH against concentration

Same acid or base from 10⁻⁶ to 1 mol/L. The dot is your solution.

Show the Larzscript program that just ran
Run a calculation to see the exact program.

This is the real program the page sent to the Larzscript interpreter (compiled to WebAssembly) in your browser. The library it imports is the same code the automated tests check.

The formulas

pH = −log₁₀[H⁺]    pH + pOH = 14 (25 °C)    Ka = [H⁺][A⁻] / [HA]

For a weak acid of total concentration c, [A⁻] = c·Ka/(Ka + [H⁺]) and the charge balance is [H⁺] = [A⁻] + Kw/[H⁺]. Written out this is a cubic in [H⁺], which the calculator solves by bisection to full double precision. The familiar approximation [H⁺] ≈ √(c·Ka) is just the first step of that solution.

Worked examples, computed above

What is verified

Fifteen weak-acid cases, four weak bases and forty-four titration points are compared with the exact cubic equation solved in 60-digit decimal arithmetic; they agree to better than 10⁻¹⁰ in pH. Strong acids are compared with the exact quadratic. Textbook values (0.1 M HCl pH 1, 0.1 M acetic acid 2.88, 10⁻⁸ M HCl 6.98) are asserted, and mutation tests confirm the checks fail if the water term or the approximation changes.

Limits: ideal solutions at 25 °C, monoprotic acids. For mixtures of a weak acid and its salt use the buffer pH calculator; for a strong-base titration use the titration curve calculator.

Frequently asked questions

How do you calculate pH?

pH = −log₁₀[H⁺], with the concentration in mol/L. A strong acid such as HCl is fully dissociated, so 0.1 M HCl has [H⁺] = 0.1 and a pH of 1.0000. For a weak acid you first need [H⁺] from the equilibrium, which this calculator solves exactly.

What is the pH of a weak acid solution?

It depends on both concentration and pKa. 0.1 M acetic acid (pKa 4.76) has a pH of 2.8829 and is only 1.310% ionised; 0.1 M hydrofluoric acid (pKa 3.17) is stronger, pH 2.1028, 7.891% ionised.

Why isn't a 10⁻⁸ M acid solution at pH 8?

Because pure water already supplies 10⁻⁷ M H⁺, and an acid can never make a solution basic. Solving the full charge balance gives pH 6.9783 for 10⁻⁸ M HCl. The textbook shortcut −log(10⁻⁸) = 8 fails for very dilute solutions; this calculator does not use it.

What is the pH of a strong base?

Find pOH = −log₁₀[OH⁻] and use pH = 14 − pOH at 25 °C. 0.01 M NaOH has pOH 2 and pH 12.0000. For bases with two hydroxides per formula unit, such as Ba(OH)₂, enter twice the concentration.

What is pKa, and how do I find pKb?

pKa = −log₁₀Ka, so a smaller pKa means a stronger acid: acetic acid 4.76, formic acid 3.75, hydrofluoric acid 3.17, ammonium 9.25. For a base, pKb = 14 − pKa of its conjugate acid; ammonia is 4.75.

Does it use the 'x is small' approximation?

No. It solves the complete charge balance [H⁺] = [A⁻] + [OH⁻] numerically to about 15 digits, so it stays correct for very weak, very dilute or fairly strong 'weak' acids where the shortcut is wrong by several percent.

How accurate is it at high concentration?

It assumes ideal solutions (activity = concentration) and 25 °C (Kw = 10⁻¹⁴). Above about 0.1 M real activities differ and measured pH deviates from the ideal value; polyprotic acids are treated as monoprotic (first dissociation).

Every number on this page is computed by the open-source larzscript-chem library (chemistry, physconst, physmath), written in Larzscript, and checked against independent references in its test suite. How it is verified →