Constipation can play a part in causing bad gas. During constipation, food is being fermented in the digestive tract for an extended period of time. As a result, when the digested food is finally expelled, any accompanying gas can be especially foul.