A buffer solution has a large reservoir of weak acid HA and its conjugate base A–.
Buffer solutions resist changes in pH when a small amount of H+ is added because most of the added H+ reacts away with A– forming HA.
A– + H+ –> HA
Similarly, buffer solutions resist changes in pH when a small amount of OH– is added because most of the added OH– reacts away with HA forming H2O and A–.
HA + OH– –> H2O + A–
Looking at this a bit more closely, we can start from the KA expression and make [H+] the subject, remembering that in this situation [H+] does not equal [A–].
This shows that the [H+] is directly proportional the HA/A– ratio.
There is such a large reservoir of HA and A- in the buffer, that the HA/A– ratio changes very little when a small amount of H+ or OH– are added so [H+] changes very little, so pH changes very little too.
Also – an important but underappreciated result – if distilled water was added, both [HA] and [A–] would decrease by exactly the same factor. This means that the [H+] would be unchanged and so would the pH.