Here is a very simple example of how the law of comparative advantage functions. (To be clear, in the real world, things are much more complicated and less straightforward than this, so we’re simplifying for clarity.) In the diagram below, we have two countries: Red and Black country. These two countries can each produce two goods: Good X and Good Y.
Red Country has an Absolute Advantage over Black Country in producing both goods, but since their production possibility curves don’t meet, their costs are different, and there is room for specialization. Red should specialize in Good Y, and Black should specialize in Good X.
For Red, 1 unit of Good X ‘costs’ 5/7 or 0.71 units of Good Y, while for Black, 1 unit of X ‘costs’ 0.67 units of Good Y. Consequently, it is cheaper for Black to produce Good Y than it is for Red to produce the same good. Likewise, we can calculate that Red has a comparative advantage in creating Good Y.