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.