In economics, David Ricardo is credited for the principle of comparative advantage to explain how it can be beneficial for two parties (countries, regions, individuals and so on) to trade if one has a lower relative cost of producing some good. What matters is not the absolute cost of production but the opportunity cost, which measures how much production of one good is reduced to produce one more unit of the other good. Comparative advantage is a key economic concept in the study of free trade.
Under the principle of absolute advantage, developed by Adam Smith, one country can produce more output per unit of productive input than another. With comparative advantage, even if one country has an absolute advantage in every type of output, the disadvantaged country can benefit from specializing in and exporting the product(s) with the largest opportunity cost for the other country.
Comparative advantage was first described by Robert Torrens in 1815 in an essay on the Corn Laws. He concluded it was England's advantage to trade with Poland in return for grain, even though it might be possible to produce that grain more cheaply in England than Poland.
However it is usually attributed to David Ricardo who explained it clearly in his 1817 book On the Principles of Political Economy and Taxation in an example involving England and Portugal. In Portugal it is possible to produce both wine and cloth with less work than it takes in England. However the relative costs of producing those two goods are different in the two countries. In England it is very hard to produce wine, and only moderately difficult to produce cloth. In Portugal both are easy to produce. Therefore while it is cheaper to produce cloth in Portugal than England, it is cheaper still for Portugal to produce excess wine, and trade that for English cloth. And conversely England benefits from this trade because its cost for producing cloth has not changed but it can now get wine at closer to the cost of cloth.
The conclusion drawn from this is that a country should specialize in products and services in which they have a comparative advantage. They should then trade with another country that has products in which that country has a comparative advantage. In this way both countries become better off.
Two men live alone in an isolated island. To survive they must undertake a few basic economic activities like water carrying, fishing, cooking and shelter construction and maintenance. The first man is young, strong, and educated and is faster, better, more productive at everything. He has an absolute advantage in all activities. The second man is old, weak, and uneducated. He has an absolute disadvantage in all economic activities. In some activities the difference between the two is great; in others it is small.
Is it in the interest of either of them to work in isolation? No, specialization and exchange (trade) can benefit both of them.
How should they divide the work? According to comparative, not absolute advantage: the young man must spend more time on the tasks in which he is much better and the old man must concentrate on the tasks in which he is only a little worse. Such an arrangement will increase total production and/or reduce total labour. It will make both of them richer.