Economics calculator

Comparative Advantage Calculator

Enter what two producers can each make of two goods, and see each one's opportunity cost, who has the absolute advantage, who has the comparative advantage.

Calculator

Producers & goods

Output per unit of resource (labor, land, or time)

Illustrative trade

Must be strictly between 1 and 2 for both sides to gain.

Country A has the absolute advantage in both goods, yet comparative advantage still splits between the two producers — this is the central, non-obvious result of the model: absolute advantage in everything doesn't remove the gains from trade.

Comparative advantage

Wheat: Country B

Cloth: Country A

Absolute advantage

Wheat: Country A

Cloth: Country A

Formula verified 16 August 2026

Country A

Country B

Opp. cost of Wheat

2 Cloth

1 Cloth

Opp. cost of Cloth

0.50 Wheat

1 Wheat

Gains from trade at 1.50 Cloth/Wheat

Country B specializes in Wheat, Country A specializes in Cloth. Trading 3 Wheat for 4.50 Cloth: the Wheat importer pays 4.50 Cloth instead of the 6 Cloth it would cost to produce that Wheat domestically — a saving of 1.50 Cloth. Likewise, the Cloth importer saves 1.50 Wheat versus producing that Cloth itself.

What this tool shows

And the trade rate range where specializing and trading leaves both sides better off — with a worked gains-from-trade figure, not just a verdict.

  • Opportunity cost of each good, for each producer
  • Which producer has the absolute advantage in each good
  • Which producer has the comparative advantage in each good
  • The trade-rate range where both sides gain
  • Gains from trade at a chosen rate and quantity
Opportunity cost for both producers Absolute vs. comparative advantage Mutually beneficial trade range Transparent formula

A teaching model — real trade involves far more than two goods.

Updated 16 August 2026

Comparative advantageHaving a lower opportunity cost at producing something than someone else — the basis for gains from trade. is about opportunity cost, not raw output — even a producer that makes more of everything can still gain from specializing in whichever good it gives up the least to produce, and trading for the rest.

At a glance

Formula shown
Opportunity cost of a good = the other good's output ÷ this good's output. Lower opportunity cost = comparative advantage.
Scenario support
Any two producers, two goods, and a trade rate within the mutually beneficial range.

Opportunity cost is one division, done four times

Divide each producer’s output of one good by its output of the other and you have the opportunity cost of that good: the amount of the other good given up to produce one more unit of it, derived directly from the four output figures you enter. Four numbers in, four opportunity costs out, and the comparison that matters runs down each good’s column — whichever producer has the lower opportunity cost for a given good has the comparative advantage in it. That is all comparative advantage is: the ability to produce a good at a lower opportunity cost than another producer, not necessarily to produce more of it in absolute terms. Absolute advantage is the other measure, and a much blunter one — simply producing more of a good than another producer using the same amount of resource, a comparison of raw output rather than of what each side gives up to get it.

The same trade-off for a single decision is worked through in how to calculate opportunity cost.

Opportunity costThe value of the next-best option you give up when you choose one thing over another.

opp. cost of X = output of Y ÷ output of X

How much Y a producer gives up to make one more unit of X, from what it could produce of each with the same resource.

Gains from trade

gain = (quantity × domestic opp. cost) − (quantity actually paid via trade)

Positive whenever the trade rate sits between the two producers’ opportunity costs.

The opportunity-cost table under the two advantage cards is where the comparative-advantage verdict actually comes from, so you can check the arithmetic yourself rather than trust a label. Not output, not skill, not who is better at making things: how much of one good a producer must give up to make one more unit of the other is the only quantity being measured anywhere on this page.

Country A outproduces B in both goods and still loses Wheat

Country A can produce 10 units of Wheat or 20 units of Cloth with its resource; Country B can produce 6 Wheat or 6 Cloth. A’s opportunity cost of Wheat is 2 Cloth (20÷10); B’s is just 1 Cloth (6÷6) — so B has the comparative advantage in Wheat, even though A produces more of both goods outright (A has the absolute advantage in both). A’s opportunity cost of Cloth is 0.5 Wheat against B’s 1 Wheat, so A has the comparative advantage in Cloth.

That split is not an accident of these four numbers. A producer can hold both the absolute and the comparative advantage in one good, but never in both goods at once, because opportunity costs are mirror images of each other for the same producer: a lower opportunity cost in one good forces a higher one in the other. Absolute advantage asks who makes more; comparative advantage asks who gives up less to make it. So the two advantage cards answer different questions and do not have to name the same producer — which is the central, often counterintuitive result of the model. Even the most productive economy still gains from specializing and trading.

Trade 3 Wheat at 1.5 Cloth each and both sides gain 1.5 units

A mutually beneficial trade rate is any rate strictly between the two producers’ opportunity costs for the traded good. In the figures above that band runs from 1 to 2 Cloth per Wheat, and at its midpoint — 1.5 Cloth per Wheat — trading 3 Wheat for 4.5 Cloth saves the Wheat-importer 1.5 Cloth and the Cloth-importer 1.5 Wheat, compared to each producing that amount domestically instead. The endpoints of the band are the two producers’ own opportunity costs, so a rate sitting exactly on one leaves that side with nothing to show for the trade.

Inside the band both sides pay less through trade than they would to produce the good themselves; outside it, one side would be better off not trading at all. That is a general mathematical result, true for any quantity traded at such a rate, not a property of these particular numbers. The gains are measured against each importer’s own domestic opportunity cost for the traded quantity — not against a specific pre-trade consumption bundle, which would depend on assumptions this calculator does not need to make. The gains panel appears only when a comparative advantage exists: identical opportunity costs on both sides mean there is nothing to gain from trading, and it stays hidden.

Where the straight line behind every result stops fitting

Each producer here holds a fixed amount of one resource — labor, land, or time — that can be split between producing either good, with constant output per unit of resource and no economies of scale. That is what makes the production frontier a straight line and each opportunity cost a single number rather than a schedule. Real production usually shows increasing opportunity costs as resources shift between uses, so the further a producer moves toward full specialization, the more a constant cost understates what the last units really cost. The model also assumes resources move freely between the two goods, when in reality retraining workers or repurposing land and capital takes time and carries its own cost. Neither limitation is repaired by entering better numbers: both are built into the shape of the model.

Two goods, two producers, and no tariffs in the arithmetic

The model runs exactly two goods and two producers, while real economies produce and trade far more than two goods with far more than two trading partners. It ignores transport costs, tariffs, exchange rates, and other frictions that affect real trade but have nothing to do with comparative advantage itself, so the band it reports is a theoretical range of trade rates rather than a landed price. Read the output as a teaching result about the gains from specialization, not as a forecast of what any real country or company should actually produce. It also does not compute revealed comparative advantage: RCA is a different, empirical measure used in real trade statistics, comparing a country’s actual export share of a good to that good’s share of world trade, and it needs trade-flow data this page never asks you for.

One decision-maker or two producers: which page to open

This page takes two producers’ output of two goods and returns each producer’s opportunity cost, which one holds the comparative advantage in each good, which holds the absolute advantage, and the range of trade rates where specializing and trading benefits both sides. Use the Opportunity Cost Calculator instead when a single decision-maker is weighing two options against each other: it covers the general two-choice version of the same idea. Come here when you are comparing two separate producers and asking whether specialization and trade between them leaves both better off — the same underlying arithmetic, applied to trade rather than to one choice.

Related calculators

Tools that build on the same economics fundamentals:

Opportunity CostCompare two choices to see net value, opportunity cost, explicit vs implicit costs, and risk-adjusted scenarios.
Production Possibilities FrontierA straight or bowed-out PPF for two goods: the opportunity cost of one more unit anywhere on it, points A to F, and whether a combination is efficient, wasteful or out of reach.
Market EquilibriumSolve equilibrium price and quantity from linear demand and supply, with surplus, a shift simulator, and tax incidence.
Diminishing ReturnsTurn input-output data into total, marginal, and average product and find the point of diminishing returns.
Marginal UtilityTurn a utility table into total and marginal utility and utility per dollar, and find the satiation point.
Price Elasticity of DemandMeasure price elasticity of demand (midpoint and simple PED) and test how a price change affects revenue and profit.
Consumer SurplusFind the value buyers gain above what they pay, from the choke price, market price, and quantity sold.
Producer SurplusFind the value sellers gain above their minimum acceptable price, from the market price and quantity sold.
Deadweight LossSize the welfare triangle a per-unit tax destroys, alongside the tax revenue it actually raises.
Global Import DutyEstimate customs duty, tax, and total landed cost for any country, or India’s Basic Customs Duty, Social Welfare Surcharge, and IGST cascade.
DDP vs DAP CostCompare landed cost under DAP and DDP Incoterms — what the buyer pays upfront vs. at delivery, and the DDP handling fee.

More in Economics, or browse all calculators.

Sources

Disclaimer

This calculator is for educational purposes only. It illustrates the classic two-producer, two-good Ricardian model of comparative advantage — a simplified teaching model, not a forecast or a real trade-policy tool. Real-world trade involves many goods, transport costs, tariffs, exchange rates, factor mobility, and changing productivity, none of which this model captures. It does not calculate the empirical "revealed comparative advantage" index used in trade statistics — the section on what this model leaves out covers that distinction.

How we calculate · Found an error? email us

Cite this calculator

APA

Sudha, J. (2026, August 16). Comparative Advantage Calculator. Calculator Matters. https://calculatormatters.com/economics/comparative-advantage-calculator/

MLA

Sudha, Jay. "Comparative Advantage Calculator." Calculator Matters, 16 Aug. 2026, https://calculatormatters.com/economics/comparative-advantage-calculator/.

Defined in the glossary: Comparative Advantage.

Authorship & verification

Built and maintained by .

How this calculator is tested

25 automated cases pass; last run 30 September 2026.

Test cases by kind
Golden14worked by hand, the arithmetic written into the test
Boundary7zero, negative, extreme and invalid inputs
Property4rules that must hold for any input

Cases from this calculator’s own test file, as written there:

  • opCostXA (20/10) (golden)
  • opCostYA (10/20) (golden)
  • opCostXB (6/6) (golden)
  • opCostYB (6/6) (golden)
  • absAdvX: A produces more X (10>6) (golden)
  • absAdvY: A produces more Y (20>6) (golden)

Full verification report for this calculator

What's changed (1 update)

Published 16 August 2026

  1. Published the comparative advantage calculator: comparative and absolute advantage between two producers and two goods, plus the gains-from-trade range.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.