Bacteria obtain energy by either ingesting other organisms and organic compounds or by producing their own food. The bacteria that produce their own food are called autotrophs. Bacteria that must consume other organic molecules for energy are called heterotrophs.
There are two general types of heterotrophs. Some heterotrophs supply all of their energetic needs by dissolving and absorbing or ingesting other organisms, and are called chemotrophic heterotrophs. By contrast, some bacteria produce some of their own energy by harnessing sunlight, but make up the balance of their energy needs by absorbing organic molecules.
Autotrophs also occur in two primary types. There are chemotrophic autotrophs, which absorb inorganic molecules, such as sulfides, and convert them to energy, as well as phototrophic autotrophs that produce their own energy by absorbing sunlight. As a whole, bacteria obtain their energy in a variety of ways, enabling some type of bacteria to live almost everywhere.
Aside from these four groups of bacteria that obtain energy in different ways, bacteria respire in different ways as well. Many organisms are aerobic, and rely on oxygen, just as animals do. Other bacteria are anaerobic, meaning that they live in an environment without oxygen. Still other bacteria can live in either oxygen-rich or oxygen-depleted environments. These flexible bacteria are called facultative anaerobes.