Deriving Henderson-Hasselbalch and noting its limits
The Henderson-Hasselbalch equation comes from rearranging the acid dissociation constant expression assuming equilibrium acid/base concentrations equal their initial values. This holds when [H⁺] is small relative to buffer species, but for very dilute buffers, that fails and water autoprotolysis becomes important. In such cases, one must solve a quadratic equation for [H⁺] incorporating mass and charge balance, yielding a more accurate pH than Henderson-Hasselbalch predicts.
For a monoprotic weak acid the equilibrium
[
\mathrm{HA;\rightleftharpoons;H^+ + A^-}
]
is characterised by
[
K_{\rm a}=\frac{[\mathrm{H^+}][\mathrm{A^-}]}{[\mathrm{HA}]},.
]
If you rearrange this to make ([\mathrm{H^+}]) the subject and take negative logarithms you obtain
[
[\mathrm{H^+}]=K_{\rm a},\frac{[\mathrm{HA}]}{[\mathrm{A^-}]}\quad\Rightarrow\quad
-\log[\mathrm{H^+}]=-\log K_{\rm a}+\log\frac{[\mathrm{A^-}]}{[\mathrm{HA}]},
]
or, using the definitions (pH=-\log[\mathrm{H^+}]) and (pK_a=-\log K_a),
[
pH = pK_a + \log\frac{[\mathrm{A^-}]}{[\mathrm{HA}]}.
]
This is the familiar Henderson–Hasselbalch equation. In buffer calculations one usually goes a step further and replaces the equilibrium concentrations ([\mathrm{HA}]) and ([\mathrm{A^-}]) by their analytical values, on the grounds that the dissociation/association of H⁺ only slightly perturbs the large reservoir of acid and conjugate base.
The simplicity of the Henderson–Hasselbalch form rests on those approximations: that ([\mathrm{H^+}]) is small compared to the total acid/base present, and that the self‑ionisation of water can be neglected. When the total buffer concentration becomes very low, those assumptions break down. The gain or loss of a few micromoles of H⁺ shifts ([\mathrm{HA}]) and ([\mathrm{A^-}]) appreciably, and the (10^{-7},\mathrm{M}) of H⁺/OH⁻ from water is no longer negligible.
If you retain the change in concentrations, the mass balance ([\mathrm{HA}]+[\mathrm{A^-}]=C_{\rm HA}) and write ([\mathrm{A^-}]=C_{\rm A^-}+[\mathrm{H^+}]-[\mathrm{HA}]), the equilibrium condition becomes
[
K_a = \frac{[\mathrm{H^+}](C_{\rm A^-}+[\mathrm{H^+}])}{C_{\rm HA}-[\mathrm{H^+}]}.
]
Rearranging gives a quadratic in ([\mathrm{H^+}]),
[
[\mathrm{H^+}]^2 + (C_{\rm A^-}+K_a)[\mathrm{H^+}] - K_a C_{\rm HA} = 0,
]
which must be solved to get the pH. Inclusion of (K_w) introduces a further term. Only in the limit ( [\mathrm{H^+}]\ll C_{\rm HA}, C_{\rm A^-} ) does the quadratic reduce to the logarithmic Henderson–Hasselbalch expression.