The energy available to living systems comes from the sun. Plants that contain chlorophyll capture light energy and store it in sugars using a process called photosynthesis. Autotrophs are organisms that can make their own food. Once the plants have store this energy, it is available for use by them, or other organisms in an ecosystem. The release of energy from stored sugars is called respiration. It is important to remember here that plants use respiration to grow and conduct other activities of life just as much as animals do.
Animals cannot make their own food, so we call them heterotrophs. Animals must eat plants, or other animals to use the energy stored. Digestion breaks down this food into glucose, which then is converted to ATP by either the Kreb's cycle or anaerobic fermentation. This process is never even close to 100% efficient, especially in warm blooded animals. Therefore, each time a smaller animal is eaten by a larger one, much of the energy stored in the body of the prey is wasted as heat energy and not converted to ATP. This is why we expect to find smaller total biomass of top predators than herbivores in a food chain. It is also rare that a food chain will have more than 4 levels before the top is reached, and the energy is release by decomposers acting on the body of the top predator.
So never forget, energy is never created or destroyed. Also, every time
it is transferred from one organism to another, this transfer is never
100% efficient.
LINK TO FOOD CHAINS, PYRAMIDS, AND FLOW OF ENERGY THROUGH AN ECOSYSTEM