According to dental hygiene experts, halitosis is caused by bacterial activity in the mouth.
"Bacteria in your mouth feed off mucus, food remnants and dead tissue cells," says professor Mel Rosenberg in a TED-Ed video. "In order to absorb nutrients through their cell membranes they must break down the organic matter into much smaller molecules. For example, they'll break proteins into their component amino acids and then break those down even further into various compounds. Some of the foul-smelling byproducts of these reactions, such as hydrogen sulfide and cadaverine, escape into the air."
To avoid this bacterial activity, practice good oral hygiene and practice it often! That means brushing your teeth after each meal, flossing at least once a day, and making regular trips to see your dentist for professional cleanings.