The problem is oligosaccharides, or “several-unit” sugars, which are produced by legumes, especially in the final stages of seed development.
The oligosaccharides, called raffinose, stachyose and verbascose, are used by the seeds to store energy.
The human body lacks enzymes to break them down, and so cannot digest and absorb them as it does the simple sugars. Instead, they are digested in the colon by normal intestinal bacteria.
In their metabolic process, the bacteria produce various gases, including carbon dioxide and hydrogen.
The problem sugars are also found in cabbage-family vegetables, among many others, and in whole grains, brans and some other seeds.
Soaking beans with frequent water changes and boiling them will help break down the sugars, as will germination into bean sprouts and fermentation into tofu.
A commercial product called Beano, containing the enzyme alpha-galactosidase, which breaks up the sugars, may also help.