The most straightforward case for free trade is that countries have different absolute advantages in producing goods. For example, because of differences in soil and climate, the United States is better at producing wheat than Brazil, and Brazil is better at producing coffee than the United States. Obviously both countries are better off when Americans produce wheat and exchange a portion of it for some of the coffee that Brazilians produce. No, as the English economist David Ricardo first explained in the early 1800s. A country can have an absolute advantage in the production of a good without having a comparative advantage.
Comparative advantage is what determines whether it pays to produce a good or import it.
Assume that there are only two goods, cars and computers, and one productive resource which is some composite of land, labor, and capital. It may seem that Americans can realize no gain by trading with Brazilians. Because it costs more to produce computers in the United States than in Brazil. All costs are opportunity costs. The cost of producing computers is the cars that could have been produced.