Swaps are derivatives, or contracts, where two parties exchange their cash flows (sometimes called ‘legs’). The most common swap concerns interest rates, one leg being fixed, the other leg being floating.
Suppose person A has a variable interest rate on a loan at 4% per year. They’re concerned that this interest rate will exceed 5% per year. Person B, who can tolerate the risk of a floating rate, offers for person A to pay them a fixed rate of 5% to satisfy person A’s desire for certainty. Person B wins money if the interest rate doesn’t exceed 5% over the term of their swap contract.
Fundamentally, swaps exist to enable parties who seek certainty and parties who seek risk to both get what they want. This is basically the same idea behind how insurance companies operate.