The idea: trade on the lower opportunity cost

Two countries, A and B, each have 120 labour hours and make two goods, wheat and cloth. A makes a tonne of wheat in 1 hour and a bolt of cloth in 2 hours. B needs 4 hours and 3 hours. A is faster at both. Does A still gain from trading with B? David Ricardo's answer (1817) was yes, and so does B. The reason is opportunity cost: what else the same hours could have made.

Two production-possibility frontiers. Country A: a straight line from 60 cloth to 120 wheat, slope 2 wheat per cloth, with the before-trade point at 60 wheat, 30 cloth. Country B: a smaller line from 40 cloth to 30 wheat, slope 0.75 wheat per cloth, with the before-trade point at 15 wheat, 20 cloth.
Each frontier shows everything a country can make with its 120 hours; its slope is the opportunity cost of cloth.

The line is the production-possibility frontier (PPF). Every point on it uses all 120 hours. Points inside waste hours, and points outside are out of reach on your own. Before trade, each country splits its hours 60/60: A makes and uses 60 W + 30 C, B makes and uses 15 W + 20 C.

Opportunity cost

For A, one bolt of cloth takes 2 hours, and those 2 hours could have made 2 tonnes of wheat. So 1 cloth costs A 2 wheat. For B, one bolt takes 3 hours, and 3 hours make only 0.75 wheat (wheat takes B 4 hours a tonne). So 1 cloth costs B 0.75 wheat. Wheat is the other way round (Demo: A is better at both, both still gain).

CountryHours per wheatHours per cloth1 cloth costs1 wheat costs
A122 wheat0.5 cloth
B430.75 wheat1.33 cloth

Absolute vs comparative advantage

A country has an absolute advantage in a good when it makes it with fewer hours. A has it in both goods. A country has a comparative advantage in a good when its opportunity cost is lower. Here A has it in wheat (0.5 cloth vs 1.33) and B in cloth (0.75 wheat vs 2). Both countries always have a comparative advantage in something. If one country gives up less wheat for cloth, it must give up more cloth for wheat, because the two costs are reciprocals. Only if the two costs were equal would trade bring no gain.

Specialize: the world makes more

Each country moves along its frontier toward its cheap good. B puts all 120 hours on cloth: 40 C. A moves 30 hours from cloth to wheat: 90 W + 15 C. A keeps some cloth, because B's 40 bolts are fewer than the 50 the world used before.

A makesB makesWorld
Before trade60 W, 30 C15 W, 20 C75 W, 50 C
After specializing90 W, 15 C0 W, 40 C90 W, 55 C

The hours are the same, but there are 15 more tonnes of wheat and 5 more bolts of cloth. Each good is now made more where it costs less.

Trade: using a bundle outside your own frontier

B ships 18 bolts of cloth to A. At a price of 1 cloth = 1.5 wheat, A pays 27 tonnes of wheat. A then uses 63 W + 33 C and B uses 27 W + 22 C. Both have more of both goods than before. Making A's bundle alone would take 63 + 33 × 2 = 129 hours, and B's 27 × 4 + 22 × 3 = 174 hours. Both are more than 120, so each point lies outside the country's own frontier. The green after-trade line through the production point shows every bundle the country can reach by trading at that price.

Country A and country B frontiers after trade at 1 cloth = 1.5 wheat. A makes 90 wheat, 15 cloth and uses 63 wheat, 33 cloth, above its frontier. B makes 40 cloth and uses 27 wheat, 22 cloth, above its frontier. The green after-trade lines run through the production points.
After trade each country uses a bundle beyond its own frontier: something it could not make alone.

The price must sit between the two costs

The price of cloth in wheat is the terms of trade. B will sell cloth only for more than the 0.75 wheat it costs B to make. A will buy cloth only for less than the 2 wheat it costs A. So both gain only if the price lies between 0.75 and 2. Inside that range the price decides how the extra 15 W + 5 C is split.

A price line from 0 to 3 wheat per cloth. Below 0.75 B loses, between 0.75 and 2 both gain, above 2 A loses. At exactly 0.75 B gains nothing, at exactly 2 A gains nothing.
Both countries gain only when the price of cloth lies between B's cost (0.75 wheat) and A's cost (2 wheat).
1 cloth =A usesB usesWho gains
0.5 wheat81 W, 33 C9 W, 22 CB loses: 102 h at home < 120
0.75 wheat76.5 W, 33 C13.5 W, 22 CB gains nothing, A gains it all
1.5 wheat63 W, 33 C27 W, 22 Cboth gain
2 wheat54 W, 33 C36 W, 22 CA gains nothing, B gains it all
2.5 wheat45 W, 33 C45 W, 22 CA loses: 111 h at home < 120

At 2 wheat a bolt, A's bundle of 54 W + 33 C takes exactly 120 hours to make at home. It sits on A's frontier, so trade does A no good (Demo: price at A's own cost). At 2.5, A pays more for cloth than it costs A to make, and its bundle falls inside its frontier: A would refuse (Demo: price too high). At 0.5, B is the one that loses (Demo: price too low).

The same idea, doing each task where its cost per unit is lowest, drives the greedy choice in the Fractional Knapsack.

What the page leaves out

Labour is the only input, costs stay constant (straight frontiers), and there are no transport costs, tariffs, money or exchange rates. The traded amount is fixed at 18 bolts; in a full model, each country's demand sets both the amount and the price. Real frontiers bend outward because resources fit some goods better than others, so specialization is usually partial. Inside each country some workers and firms lose from trade even when the country gains (Stolper–Samuelson). The Heckscher–Ohlin model explains comparative advantage by land, labour and capital rather than by labour productivity.