The balance of payments is simply a double-entry accounting system; it's based on corresponding debits and credits. Its purpose is to record payments and receipts from the residents of one country with residents of all other countries.
It's important to distinguish between the balance of payments and the current account. When the terms "trade deficit" and "trade surplus" are used in media, they are almost always referenced to the current account. The current account is just one part of the overall balance of payments, which also contains the capital account and financial account.
When Balance of Payments Runs a Deficit
According to theory, it's impossible to sustain a deficit in the balance of payments. In practice, temporary imbalances do occur because of accounting difficulties.
In double-entry accounting, payments and receipts are necessarily equal. Thus, the balance of payments must theoretically always be equal as well. All current account transactions – what is normally thought of as international trade – are canceled out by capital and financial account transactions.
To see how this works, consider a scenario wherein Americans purchase $100 million in cars from German automakers, but Germans do not purchase anything from American businesses. Most Americans don't regularly hold euros, so the vast majority of those purchases are made in dollars.
Since the Germans aren't using those dollars to purchase U.S goods in this scenario, they have no choice but to hold deposits in U.S. banks or make other dollar-based investments in the U.S. The current account shows a deficit with Germany of $100 million. That is balanced out by a surplus in the capital and financial accounts, where $100 million worth of payments are made from the Germans to individuals, businesses, and banks in the U.S.
What Causes Deficits in Balance of Payments?
The most obvious cause of a balance of payments deficit is called a "unilateral transfer." For example, U.S. residents who send money in the form of foreign aid to another country do not receive anything in return (economically speaking). Few economists would suggest that balance of payment deficits resulting from foreign aid are a "bad thing."
However, no accounting system is perfect. Most accounting rules are, in some sense, arbitrary and subject to timing irregularities. It gets particularly tricky to account for changes in value in the foreign exchange market. Those transactions are normally broken out and treated separately on one side of the balance of payments equation.
The flow of money (including gold) between central banks and treasuries is particularly sensitive to exchange-rate fluctuations. This often results in short-term deficits or surpluses from excess payments or receipts. In other words, the transactions that are recorded in the current and financial accounts might not balance out because of irregularities with the capital account.
The balance of payments is theoretically a monetary phenomenon. It implies the existence and value of money. According to this theory, a deficit in the balance of payments is a mechanism that adjusts an excess supply of money between the instance and recording of a transaction.
In the short-term, a balance of payments deficit isn't necessarily bad or good. It does mean that, in real terms, there is more importation than exportation occurring until the value of money adjusts.