Specialization refers to the tendency of countries to specialize in certain products which they trade for other goods, rather than producing all consumption goods on their own. Countries produce a surplus of the product in which they specialize and trade it for a different surplus good of another country. The traders decide on whether they should export or import goods depending on comparative advantages.
Imagine that there are two countries and both countries produce only two products. They can both choose to be self-sufficient, because they have the ability to produce both products. However, specializing in the product for which they have a comparative advantage and then trading would allow both countries to consume more than they would on their own.
One might assume that the country that is most efficient at the production of a good would choose to specialize in that good, but this isn't always the case. Rather than absolute advantage, comparative advantage is the driving force of specialization. When countries decide what products to specialize in, the essential question becomes who could produce the product at a lower opportunity cost. Opportunity cost refers to what must be given up in order to obtain some item. It requires calculating what one could have gotten if one produced another product instead of one unit of the given product.
For example, the opportunity cost to Bob of 1 bottle of ketchup is 1/2 bottle of mustard . This means that in the same amount of time that Bob could produce one bottle of ketchup, he could have produced 1/2 bottle of mustard. Tom could have produced 1/3 bottle of mustard during the time that he was making one bottle of ketchup. Tom will have the comparative advantage in producing ketchup because he has to give up less mustard for the same amount of ketchup. In sum, the producer that has a smaller opportunity cost will have the comparative advantage. It follows that Bob will have a comparative advantage in the production of mustard.
Tom has the comparative advantage in producing ketchup, while Bob has the comparative advantage in producing mustard.
There is one case in which countries are not better off trading: when both face the same opportunity costs of production. This doesn't mean that both countries have the same production function - one could still be absolutely more productive than the other - but neither has a comparative advantage over the other. In this case, specialization and trade will result in exactly the same level of consumption as producing all goods domestically.