Writing out the equilibrium expression for a weak acid in solution:
$$[\ce{H3O+}] = K_\mathrm a\frac{[\ce{HA}]}{[\ce{A-}]}$$
Buffers need to keep the concentration of the weak acid to its conjugate base similar in order for it be effective.
Let’s say you add a small amount of base. Some of the $\ce{HA}$ molecules are converted into $\ce{A-}$ ions. The ratio $\frac{[\ce{HA}]}{[\ce{A-}]}$ changes but not by a large amount.
If we add a small amount of acid, we generate more $\ce{HA}$. Again, the ratio $\frac{[\ce{HA}]}{[\ce{A-}]}$ changes but not by a large amount.
Why do buffers for the acid needs to be weak?
If you look at the expression, the concentration of hydronium ions is directly related to the ratio of the conjugate acid and its base. If you take a strong acid for instance, hydrochloric, it will almost completely deprotonate in water. Thus the ratio of $\frac{[\ce{HA}]}{[\ce{A-}]}$ is close to 0 and is negligible, and we use the $K_\mathrm a$ to directly find the concentration of hydronium ions. As strong acids have very large $K_\mathrm a$ values, we can directly take the concentration and assume that will be the concentration of our hydronium ions.
Why doesn’t the conjugate base react with the acid?
It depends on the acid. In buffer solutions, competition arises between acid and the conjugate base. For instance, if the $K_\mathrm a$ is large relative to $10^{-7}$, the acid ionization will proceed and you will have an equilibrium with the conjugate base reacting with its acid resulting in no buffer action.
If however, the tendency of the acid in donating hydrogen ions, say, to water, is outcompeted by the tendency of the base to accept those hydrogen ions from water, this net reaction produces $\ce{OH-}$ ions, the $K_\mathrm a$ of this acid-base pair is less than $10^{-7}$, and we use $K_\mathrm b$ to find equilibrium.
Derivation of the Henderson–Hasselbalch equation:
Let’s use acetic acid and water as an example:
$$\ce{AcOH + H2O <=> AcO- + H3O+} $$
$$ K_\mathrm a = \frac{[\ce{AcO-}][\ce{H3O+}]}{[\ce{AcOH}]}$$
Taking the log of both sides:
$$ \log(K_\mathrm a) = \log\left(\frac{[\ce{AcO-}][\ce{H3O+}]}{[\ce{AcOH}]}\right)$$
Using the law of logs where $\log(xy) = \log(x) + \log(y) $:
\begin{aligned}
\log\left(K_\mathrm a\right) &= \log\left(\frac{[\ce{AcO-}]}{[\ce{AcOH}]}\right) + \log([\ce{H3O+}])\\
-\log([\ce{H3O+}]) &= \log\left([\ce{AcO-}][\ce{AcOH}]\right) - \log(K_\mathrm a) \\
\mathrm{pH} &= \log\left(\frac{[\ce{AcO-}]}{[\ce{AcOH}]}\right) + \mathrm{p}K_\mathrm a \\
\mathrm{pH} &= \mathrm{p}K_\mathrm a + \log\left(\frac{[\ce{B}]}{[\ce{A}]}\right) \\
\end{aligned}
With buffer systems, you can calculate the $\mathrm{pH}$ of any buffer solution. The Henderson–Hasselbalch equation has several caveats however.
- You need have both the acid and its conjugate base in solution.
- The extent of ionization must be small enough so that the
concentrations of hydronium and hydroxide ions are small relative
$[\ce{HA}]_0$ and $[\ce{A-}]_0$.