Gastric acid
The main constituent of gastric acid is hydrochloric acid which is produced by parietal cells (also called oxyntic cells) in the gastric glands in the stomach. Its secretion is a complex and relatively energetically expensive process. Parietal cells contain an extensive secretory network (called canaliculi) from which the hydrochloric acid is secreted into the lumen of the stomach. The pH of gastric acid is 1.5 to 3.5 in the human stomach lumen, the acidity being maintained by the proton pump H/K ATPase. The parietal cell releases bicarbonate into the bloodstream in the process, which causes a temporary rise of pH in the blood, known as an alkaline tide.
Ion trapping
The charge of a molecule depends upon the pH of its solution. In an acidic medium, basic drugs are more charged and acidic drugs are less charged. The converse is true in a basic medium. For example, Naproxen is a non-steroidal anti-inflammatory drug that is a weak acid (its pKa value is 5.0). The gastric juice has a pH of 2.0. It is a three-fold difference (due to log scale) between its pH and its pKa; therefore there is a 1000× difference between the charged and uncharged concentrations. So, in this case, for every one molecule of charged Naproxen, there are 1000 molecules of uncharged Naproxen at a pH of 2. This is why weak acids are better absorbed from the stomach and weak bases from intestine where the pH is alkaline. When pH of a solution is equal to pKa of dissolved drug, then 50% of the drug is ionized, another 50% is unionized. This is described by the Henderson-Hasselbalch equation.