In his book Principles of the Political Economy (1817), David Ricardo explained his Law of Comparative Advantage, which was further refined by John Stuart Mill. It is this theory that forms the foundation of our theory of international trade.
The Law of Comparative Advantage states that trade can benefit all countries if each country were to specialize in producing the goods in which they have a comparative advantage in (i.e. able to produce at relatively lower opportunity costs) and exchange some of these goods for other types of good in which they have a comparative disadvantage in (i.e. goods in which they can produce at relatively higher opportunity costs)
This explains why many countries are dependent on others for goods which they themselves can produce on their own. A country should specialise in what it is relatively best at based on comparative advantage.
Provided opportunity costs of various goods differ in two countries, both of them can gain from mutual trade if they specialize in producing and exporting those goods that have relatively lower opportunity costs compared with the other country.