The smell is produced from the process of food breaking down which creates methane gases. Bacteria that are found in the intestines create waste of their own as well as breaking down food in the digestive process. The bacteria create compounds that have sulfur and it is the sulfur and methane gas that produce the bad smell.
Passing wind is a perfectly natural bodily function. The smell of the gas can change or become offensive for a variety of reasons, such as eating certain foods. It can also be an indicator of an unhealthy diet or bowels.