Skip to content
K Knidox Search…
Economics · Trade

Comparative Advantage Calculator

Turn a two-producer, two-good output table into opportunity costs and find who should specialise.

Units of good X that A can make.
Units of good Y that A can make.
Units of good X that B can make.
Units of good Y that B can make.
Try an example
Who specialises in what
Producer A should make Y, Producer B should make X

Absolute advantage: Producer A in X, Producer A in Y (higher raw output).

Opportunity cost of 1 X
Producer A
2 Y
Producer B
1 Y

Lower cost → Producer B has the comparative advantage in X.

Opportunity cost of 1 Y
Producer A
0.5 X
Producer B
1 X

Lower cost → Producer A has the comparative advantage in Y.

Opportunity cost of one X (lower bar has the advantage)

Comparative advantage belongs to whoever gives up the least to make a good — the lowest opportunity cost. If A makes 10 X or 20 Y and B makes 4 X or 4 Y, A’s cost per X is 2 Y while B’s is 1 Y, so B specialises in X and A in Y — even though A out-produces B on both (absolute advantage).

What comparative advantage is

Comparative advantage is the idea that a producer should make the good they sacrifice the least to produce. Every unit of one good you make costs you the other good you could have made instead — that trade-off is the opportunity cost. Whoever faces the lower opportunity cost for a good has the comparative advantage in it and should specialise there, then trade for the rest. This is the engine behind gains from trade, and it holds even when one side is better at making everything.

opportunity cost of one X = Y ÷ X · opportunity cost of one Y = X ÷ Y

X and Y are how many units of each good a producer can make with the same time or resources. The good you divide by is the one you are making; the result is how much of the other good you give up.

Worked example

Producer A can make 10 X or 20 Y; Producer B can make 4 X or 4 Y with the same resources.

  1. 1
    Write the output table. List how much of each good every producer can make: A = 10 X or 20 Y, B = 4 X or 4 Y.
  2. 2
    Cost of one X = Y ÷ X. A: 20 ÷ 10 = 2 Y per X. B: 4 ÷ 4 = 1 Y per X.
  3. 3
    Cost of one Y = X ÷ Y. A: 10 ÷ 20 = 0.5 X per Y. B: 4 ÷ 4 = 1 X per Y.
  4. 4
    Pick the lower cost for each good. X is cheaper for B (1 Y < 2 Y); Y is cheaper for A (0.5 X < 1 X).
  5. 5
    Specialise and trade. B makes X, A makes Y, then they trade — total output rises even though A has the absolute advantage in both goods.

Opportunity-cost comparison (A 10X/20Y · B 4X/4Y)

Read down each column: the producer with the lower opportunity cost has the comparative advantage in that good.

ProducerCost of 1 X (in Y)Cost of 1 Y (in X)
A20.5 ← lower
B1 ← lower1
AdvantageB specialises in XA specialises in Y

Why the “worse” producer still gains

In the example A has the absolute advantage in both goods — 10 > 4 units of X and 20 > 4 units of Y. Absolute advantage just compares raw output, so it can sit entirely with one side. Comparative advantage compares opportunity costs, and those cannot both favour the same producer: if one good is relatively cheap for you, the other is relatively cheap for the other side. That is why each producer always has a comparative advantage in exactly one good, and why specialisation plus trade leaves both better off.

This is David Ricardo’s classic argument from 1817. Even a producer who is worse at everything in absolute terms is still comparatively better at something, so there are always gains from trade — the point that turns a lopsided output table into a case for specialisation.

What is the difference between comparative and absolute advantage?
Absolute advantage is simply making more of a good with the same resources — it compares raw output. Comparative advantage compares opportunity costs: who gives up the least of the other good. One producer can hold the absolute advantage in both goods, yet each producer still has the comparative advantage in exactly one, which is what determines who should specialise.
Can a country have a comparative advantage in everything?
No — that is impossible by definition. Opportunity cost is a trade-off, so if a producer is relatively cheaper at making one good, they are automatically relatively more expensive at the other. Comparative advantage in one good forces comparative disadvantage in the other, so it can never sit on both sides of the table for one producer.
How do I compute opportunity cost from an output table?
For a producer who can make X units of one good or Y units of the other, the opportunity cost of one unit of X is Y ÷ X (the amount of the other good given up), and the opportunity cost of one unit of Y is X ÷ Y. The two costs are reciprocals of each other.
Why does the producer with the lower opportunity cost specialise?
Because they sacrifice the least to make that good. When each producer concentrates on the good with their lowest opportunity cost and trades for the rest, total output across both producers is higher than if each tried to make everything — that surplus is the gain from trade.
What if both producers have the same opportunity costs?
Then neither has a comparative advantage. The output tables are proportional (for example 4X/8Y and 2X/4Y both cost 2 Y per X), the opportunity costs match exactly, and there are no gains from specialising — trade leaves total output unchanged.
Does comparative advantage depend on the units or prices used?
No. Opportunity cost is a ratio of physical outputs, so it does not depend on money prices or the currency involved. Scaling one producer’s numbers up or down proportionally leaves the opportunity costs — and therefore the comparative advantage — unchanged.