Energy flows through an ecosystem from the sun, into plants, and up through the trophic levels (i.e. the food chain). Plants convert the sun’s energy into food, herbivores take energy from plants, carnivores take energy from herbivores. Additionally, decomposers convert matter into usable resources for plants. Some energy is lost at each level, usually via heat (the lost energy is the energy it takes animals to live, grow, and move). Therefore, the total energy in ecosystems reduces as it moves up the trophic levels; the ecosystem can support fewer carnivores than herbivores and fewer herbivores than plants.
(Picture source: Methuen.k12.ma.us)
View a longer, but simple, explanation here.