Most of them can’t. The vast majority of bacteria and viruses you eat are in fact destroyed by stomach acid.
But there are a few that are well-adapted to surviving the human digestive system, and those are the ones that can make you sick. *H. pylori*, for example, which is both a common resident of your stomach and a common cause of stomach ulcers, burrows into your stomach lining quickly to get away from the acid.
(I am assuming you’re asking about foodborne illness. As others have noted, many other routes to infect you exist that aren’t through your stomach in the first place.)
Latest Answers