Energy ultimately enters an ecosystem via sunlight. Autotrophs are plants and algae that produce their own food directly from sunlight. They do this primarily through a process called photosynthesis where sunlight is used to convert carbon dioxide and water into simple sugars like glucose for food. This food that the plants produce is the energy trapped into chemical form. Heterotrophs are animals and other organisms that cannot make their own food and must obtain nutrition through eating. So heterotrophs eat the autotrophs. The chemical food the autotrophs make is then introduced into the animal food chain. Animals lower in the food chain eat the plants and the animals higher in the food chain eat the other animals. So the energy passes up the food chain. But the process is certainly not 100% efficient. Some of the food energy is lost to the environment as heat when the food is digested and processed by the organisms for energy. Eventually, animals at all levels of the food chain die and their bodies are decomposed by soil bacteria, fungi, and microorganisms. This is their food. The carbon, nitrogen, oxygen, and various elements are then reintroduced into the soil and air to be used by autotrophs again as raw materials to make food (and again, sunlight provides the energy to make this happen). So the entire cycle continuously repeats itself.