Building on the description from @LimonadaPT, I'll try to make a simple example story with five players:
- sellers of newspapers
- buyers of newspapers
- buyers of old newspapers/sellers of cardboard boxes
- buyers of cardboard boxes
Plus a "society" that includes all five of the above, plus many people not involved in any of these steps.
First, the buyers and sellers of newspapers arrive at some equilibrium price and quantity, which gives a positive "utility" to both, and thus to society in general. However, that price and quantity is failing to account for the negative externality that people who aren't buying or selling newspapers experience, such as trash in the streets.
Second, government steps in and says, hey, if that negative externality were being taken into account, then the equilibrium price of newspapers would be higher and the quantity lower. Therefore, we slap a tax on newspapers. That would lower utility to the buyers and sellers of newspapers, but raise the total amount of utility to society.
Third, we set that aside for a moment and move on to a new problem: The makers of cardboard boxes use recycled newspaper for their product, but there's a cost associated with doing so which gets reflected in the price of cardboard boxes. The cleanup of old newspapers has a positive exeternality to society, but society isn't paying for it; only the buyers and sellers of cardboard boxes are.
So fourth, government steps in again and subsidizes cardboard boxes. This lowers costs faced by cardboard box manufacturers, which raises the quantity they produce and thus the quantity of old newspapers they recycle. This raises the utility to society.
Finally, to bring it all together, imagine government uses the tax revenue from newspapers to pay for the subsidy on collecting used newspapers. Or better yet, remove government all together and just make it a direct payment from newspaper creators to used newspaper recyclers. The transaction creating the negative exeternality now pays for the transaction creating the positive externality, raising total utility in society on both ends.
Of course, this is highly simplified. I've left out, for example, elasticity and who bears the burden of a tax. But hopefully it illustrates the general idea. The fundamental point to the whole thing is that both the sale of newspapers and the creation of cardboard boxes affect people who aren't involved in the transactions, and the transfer payment forces the market to take their considerations into account.