Carbon is the most abundant element in microorganisms. Cells of microorganism are about 50% carbon on a dry weight basis (with all water removed). Heterotrophs are microorganisms that use organic carbon for both anabolic and catabolic reaction. There are many sources of organic carbon (sugars, organic acid, fatty acids plus many more). Organic carbon will have hydrogen.
Autotrophs get their carbon from CO2 which as no hydrogen. Autotrophs get energy for catabolic reactions from inorganic chemical reactions or from sunlight.
Microbial cells are about 12% nitrogen on a dry basis. Nitrogen is needed for protein and nucleic acids. Many bacteria use NH3 as a nitrogen source. Some can use NO3-, and a very few can use N2 gas.
Phosphorous is needed for nucleic acids and phospholipids.