One of the ways (there are several) by which the kidney excretes acid (and conserves sodium) is through generation of ammonium from glutamine in the proximal convoluted tubules.
In the proximal convoluted tubule, the generated ammonium is excreted into the tubular lumen (in exchange for filtered sodium, which is not shown), where it combines with filtered chloride (not shown) to form ammonium chloride (which is then excreted). In this process, three bicarbonates are generated within the proximal tubular cell, which are then secreted into plasma along with the sodium (to maintain electroneutrality) with the NaHCO3 basolateral transporter. In this way, the kidney retains sodium, excretes chloride and generates new bicarbonate (x3), and gets rid of acid (as ammonium chloride). This is one way how the kidney compensates for a primary respiratory acidosis (reclaims bicarbonate and excretes hydrogen chloride as ammonium chloride, resulting in a secondary or compensatory hypochloremic metabolic alkalosis). The reverse occurs in a primary respiratory alkalosis, in which bicarbonate retention (and acid excretion) is reduced by decreased ammonia generation in the proximal tubules.
In the distal tubules, the kidney excretes additional acid as follows: Ammonia moves from the interstitium or blood into the lumen, where it combines with hydrogen (generated within the tubular cell from water and carbon dioxide) which is actively pumped into the renal tubular lumen by a luminal vacuolar-type H+ATPase. The single bicarbonate that is generated from carbonic anhydrase then exits the cell into blood in exchange for chloride (bicarbonate/chloride cotransporter), which passively follows H+ out, via a paracellular pathway (not shown), maintaining electroneutrality. Thus, the second way in which the kidney can also get rid of hydrogen (and retain bicarbonate) as a response to a primary respiratory acidosis is to promote the activity of the H+ATPase in the distal tubules.
Indeed, in a primary respiratory acidosis, the H+ATPase is stimulated by pCO2, which is increased in blood and readily crosses the cell membrane from blood into the renal tubular cell and decreases the intracellular pH (thus driving the reaction above). Note that aldosterone stimulates H+ATPase activity, promoting acid excretion in the distal tubules.