Bacteria are some pretty complicated and amazingly complex organisms that can perform tasks that will surprise and astound you!
First of all, in order for bacteria to succeed in his life he must eat and reproduce. And, in order to do these two actions, he needs the ability to break down structures to digestible material.
In one corner of the bacteria world you have a group of autotrophs. These bacteria can only extract energy from inorganic compounds that have roots in carbon dioxide (the inorganic version of course).
On the other hand you have a group of bacteria known as the heterotrophs. These commonly known bacteria can break down and consume organic compounds, that have a carbon base, such as sugars, fats, proteins, etc. Probably the most famous bacteria from this group is E coli. 1
This E coli can bring horrible consequences to the human who has taken it in and has caused many issues over the years.
These two groups of bacteria get their food from organic (heterotrophs) and inorganic (autotrophs) and rely on carbon (heterotrophs) and carbon dioxide (autotrophs) for bases for their food.
1 “Bacteria.” Encyclopædia Britannica. Encyclopædia Britannica 2007 Deluxe Edition. Chicago: Encyclopædia Britannica, 2012.