The answer to your question depends on the kind
of cell we are talking about. Autotrophic cells
such as plants and certain bacteria usually
generate ATP through photosynthesis or
chemosynthesis. They basically take energy from a
non-organic source, such as the sun or various
inorganic chemicals, and convert it to energy that
is "usable" by the rest of the cell and other
organisms. Ultimately this non-organic energy is
used to drive what is called an "electron
transport chain." Many enzymes are "embedded"
along the electron transport chain. These enzymes,
called ATP synthase, add a phosphate to ADP to
make it ATP. If you're wondering where the ADP
comes from, it is released as a by-product in
chemical reactions in the body that require ATP.
So there is a cycle of the following form:
1. ATP + chemical reaction or process --> ADP
2. ADP goes back to an ATP synthase to procure a
phosphate --> becomes ATP.
3. ATP goes back out to the rest of the cell to
provide energy for some other process.
Plants can also undergo cellular respiration to
produce ATP, but generally, heterotrophic
organisms, which obtain their energy by "eating"
other organisms, generate ATP during cellular
respiration. Cellular respiration converts
macromolecules, such as glucose or lipids, to
smaller molecules and energy that is "usable" by
the cell. The cellular respiration pathway has its
own version of the electron transport chain --
with different "electron carriers" and ATP
synthase enzymes than those found in