The digestive process called peristalsis is involved with farting. (If you've ever experienced a rumbling, churning sensation in your abdomen before a fart, you were probably experiencing peristalsis.)
During peristalsis, a series of muscle contractions in the digestive tract guide gas from the stomach into the anus, combining with smaller gas bubbles along the way. Nerve endings in the sphincter let a person know that a fart is waiting to be released.
Most people can voluntarily contract their sphincters to hold in a fart or relax their sphincters to release it.