A buffer is a mixture of a weak acid and its salt.
The concept of a buffer is hard to understand unless you are aware of what enables a buffer to do its job.
Please read on for more information on pH & Buffers.
The reason that a buffer works is that each acid / salt mix sets up an equilibrium in solution:
NaAcetate Na^+ + Acetate^-
Acetic Acid H^+ + Acetate^-
These two reactions are happenning in the same solution so you have an equilibrium set up between:
Acetic Acid + NaAcetate Na^+ + H^+ + 2Acetate^-
If you add an acid to that solution then you drive the reaction to the left (i.e. you add extra H^+ on the right hand side and so this sets up an imbalance. The reaction produces more Acetic Acid to maintain equilibrium and the NaAcetate dissociates to make more Na^+ and more Acetate^-). Similarly, if you add a base to the solution, you drive the reaction to the right (the OH^- from the base reacts with the H^+ in the solution to make H2O, and since the equilibrium is disrupted, the Acetic Acid breaks up into H^+ and Acetate^- and the Na^+ combines with Acetate^- to form more NaAcetate).
Out of this you notice that the concentration of H^+ does not increase, up to a point (i.e. when you have consumed all of the reactants like Acetate^-). This is the basis of the buffering capacity. The pH (aka log([H^+])) of the resultant solution (before adding acid or base) is dependent on how much H^+ as dissociated form the Acetic Acid, and where this balance lies is dependent on the dissociation constant of the Acetic Acid. The stronger the acid, the bigger percentage of the compound that is found in the H^+ + X^- rather than the HX form. Acetic Acid is a weak acid, so it does not have too much in the H^+ + Acetate^- form. So its pH is closer to 7 than 1.
Now the mash is more complicated than that above reaction, but suffice it to say that sugars can be a weak acid and salts can help make its salt. Amino acids are weak acids and salts in one and the can act as their own buffer. The mash overall is a great buffer.
Note that when you sparge, you are removing a lot of the buffering capacity of the mash and as such the pH can change much easier. Adding acid to the late sparge water can help to keep the pH more acidic but I do not worry about that myself.
http://barleyment.wort.ca/article.php?story=20040330223943704