Simple example: There are just two of us, stuck on an island. We survive by harvesting coconuts and catching rabbits.
Scenario #1 — Autarky. We each work independently, doing both tasks. Since we’re dividing our effort, neither of us gets very proficient at these tasks and it takes us each 16 hours of daily effort to scrape by, after which we collapse from exhaustion for the day.
Scenario #2 — Specialization. You are a better climber than I am, but I am a better with snares. So, we specialize, you on gathering coconuts, me on catching rabbits. By focusing on that one task we each gain greater skills in that area. We each complete our work for the day in only 12 hours after which we trade a portion of our goods with each other.
As a bonus, we now each have four hours left over before we go to sleep. This is time that could be used for leisure and relaxation. It could be used to satisfy other needs. Maybe one of us wants to try fishing, or building a boat? The time could also be used to build tools to make our main production even more efficient. For example, I may design new and better snares for catching rabbits. This might mean I can, down the road, reduce my labor to only 10 hours a day.
Whether you are talking about an island of two persons, a community, a nation or the entire world, it is the same basic mechanisms at play. There is comparative advantage (you are naturally a better climber than I am). There is specialization and division of labor (I focus on catching rabbits and become really good at that one thing.) There is capital investment (I take my free time to build tools that make my production more efficient.) And there are gains for trade (It is cheaper for me to get some of your coconut in trade than for me to take time away from rabbit hunting to get them on my own.)
Note that there are also some unstated pre-requisites that enabled the productivity gains described above. We had to agree not to kill each other or steal each other’s property. We also had to honor whatever agreements we made with each other. This “rule of law” provides the foundations on which all thriving societies are built.