This compound is crucial in keeping you alive. It is part of an acid-base buffer system in your blood plasma. The normal plasma concentration is about 25 mEq/L.

Some bicarbonate is absorbed in the gastrointestinal system, along with cloride and sodium ions. It is also one of the 6 main ingredients in bile (mmm!), and is secreted by the pancreas from the epithelial cells lining the ducts.

The kidneys regulate bicarbonate with the end goal of hydrogen ion (proton) regulation. Protons are very important in the pH balance of the blood. As bicarbonate binds protons, secretion of bicarbonate causes a stray proton to wander off into the blood, so excreting bicarbonate is equivalent to producing and secreting hydrogen ions.

The kidneys can, however produce bicarbonate by chemical means. This is the equivalent of removing protons from the blood.

As such, in the presence of alkalosis the kidneys excrete large amounts of bicarbonate, adding protons to the plasma and moving the pH back down toward neutral. Conversely, in the presence of acidosis, they produce new bicarbonate and dump it into the bloodstream, thereby binding protons and effectively removing them from the blood. This brings the pH up, toward neutral.

The mechanisms for all of this (in the kidney) are kind of obscure. I'll address both adjustments separately.

Bicarbonate Reabsorption
In the tubular epithelial cells of the nephron, carbonic anhydrase synthesizes H2CO3 from water and carbon dioxide, which are abundantly present in the epithelial cells. This dissociates into bicarbonate and protons. The bicarbonate will move down its concentration gradient into the interstitial fluid and then into the blood, while protons must be actively transported out of the epithelium into the tubular lumen. This is done by proton pumps, hydrogen-potassium ATPase and sodium-potassium countertransporters. Once it returns to the lumen, it is NOT excreted as one might expect. Rather, it combines with filtered bicarbonate there, forming H2CO3, which dissociates spontaneously into water and carbon dioxide, which can then be used to start the cycle once more. As you can see, the same bicarbonate molecule is not moved across the membrane, but there is a net decrease of one in the lumen, and increase of one in the blood.

Furthermore, if this is still not enough to compensate for acidosis, the kidney can produce new bicarbonate. If all of the filtered bicarbonate has been reabsorbed via the mechanism described above, the secreted protons will bind to a nonbicarbonate buffer, usually HPO42-. The hydrogen is then excreted as part of this ion, yielding a net gain in bicarbonate.

Finally, tubular processing of glutamine can yield new bicarbonate. It is taken up from both the interstitum and the lumen, and metabolized to form bicarbonate and ammonium. The ammonium is secreted into the tubule and then excreted, while the bicarbonate moves back to the blood.

Bicarbonate Excretion
If there is a metabolic alkalosis, this will lead to a reduced rate of proton excretion. Less bicarbonate will be broken down into carbon dioxide and water, and therefore will remain in the tubular lumen and then be excreted. Recall that excretion of bicarbonate is equivalent to adding protons to the blood, lowering the pH from its elevated state to normal. A decrease in glutamine metabolism is also induced, so very little new bicarbonate is added to the blood. The overall response to alkaline plasma is essentially just a reduction of activity in the mechanims mentioned under bicarbonate reabsorption.