Your mash alkalinity is a measurement of the mash's ability to buffer, or resist, attempts to lower its pH. It does this with the bicarbonate ions and, to some extent, the carbonate and hydroxide ions in solution. All three of these ions, bicarbonate, carbonate and hydroxide, react with hydrogen to reduce acidity (raise pH).
If you want to know more about the chemistry involved in mash alkalinity, click here,
The residual alkalinity of your mash water is another thing altogether. It was noticed by Kolbach, a German brewing scientist, that when malt is added to water, it releases phosphates. These phosphates then react with the calcium and magnesium ions in the water and release two protons. Again, you can check out the chemistry involved at the link above. It is the release of the two protons H+, which are now available to react with the bicarbonate and to an extent the carbonate ions in the water, that is important. Once the bicarbonate is all used up, the pH drops from an excess of protons (hydrons) in the mash.
Kolbach noticed that not all of the calcium or magnesium ions in solution will react with the phosphates (malt phytin) to produce the excess protons. Only 2 in 7 calcium and 1 in 7 magnesium ions will react with the malt's phosphates. This finding resulted in the definition of Residual Alkalinity, or a "measure of the alkalinity left after the acidifying reaction between the malt's phosphates and the water's calcium and magnesium has been taken into account." In fact, he found that 3.5 equivalents of calcium will react with the malt phytin to release 1 equivalent of hydrogen ions that can neutralize 1 equivalent of the water's alkalinity. Magnesium needs 7 equivalents to neutralize 1 equivalent of the water's alkalinity. So, not all the alkalinity will be "neutralized" and that alkalinity that is left over, is defined as Residual Alkalinity (often abbreviated as RA).
It is this excess, or residual, buffering capacity (remember, your mash alkalinity is a measurement of the mash's ability to buffer, or resist, attempts to lower its pH) that can cause an all-malt mash to have a higher pH than is normally desirable (greater than 6 pH). When your mash pH is greater than 6 you start extracting too many tannins from the grain husks resulting an a harsh beer.
Brewers in areas with high water alkalinity, such as Dublin, found out by trial and error that by adding highly kilned malts to the mash, the harshness was eliminated. In effect, the dark roasted malt's natural acidity overcame the mash alkalinity and reduced the mash pH to the desired level (around 5.2-5.4).
If you are having trouble with harshness or astringency, and haven't checked your mash pH, you might want to start. You can purchase a pH meter at MoreBeer.com by clicking here. For more information on adjusting mash pH, click here. I highly recommend you use John Palmer's Residual Alkalinity spreadsheet before you write your recipe.
Have a water test done at Ward Laboratories. Order the W-6 Test: Household Mineral Test for $16.50 (at the time of this writing), and check for your water's: Sodium, Calcium, Magnesium, Potassium, Carbonate, Bicarbonate, Chloride, Sulfate, Nitrate, Electrical Conductivity, Est. Total Dissolved Solids, pH, Total Hardness (Lime) and Total Alkalinity.
Once you get your water's numbers, download the spreadsheet here at John Palmer's How To Brew website. Plug in your water's numbers, your estimated SRM, and the target RA for the recipe in question. Then either dilute with RO or distilled water, add these common water adjustment salts, or add some acid. The spreadsheet will let you know what the additions do to your water and whether your chloride to sulfate ratio will make a very bitter to very malty beer. It's a very useful tool and may make a huge difference in your brewing. Understanding mash alkalinity and residual alkalinity may seem like an advanced topic, but if you can't get your beers to score well, it is worth looking into. According to John Palmer on one of the Brew Strong podcasts on water adjustment, you might be able to increase your beer's scores by as much as 10 points by correctly adjusting your residual alkalinity and chloride to sulfate ratios.
References: Information for this page on mash alkalinity was adapted from the book How to Brew by John J. Palmer, and the wiki page Understanding mash pH at www.braukaiser.com.