Consider a scenario where
- A takes out a 5% fixed rate loan, and a swap where they receive 5% fixed and pay (LIBOR + X%) floating
- B takes out a (LIBOR + 0.6%) floating rate loan, and a swap where they pay 5% fixed and receive (LIBOR + X%) floating*
The improvement that A would see on their floating rate loan is 0.1% - X% and the improvement that B sees on their fixed rate loan is 0.8% + X%. If X = -0.35% the both parties have the same improvement vs the scenario where they don't do a swap. However we also need to account for 0.1% profit margin for the bank, so we adjust the rates to -0.3% and -0.4% which means the final arrangement is
- A takes out a 5% fixed rate loan, and a swap where they receive 5.3% fixed and pay LIBOR (resulting in a floating rate at LIBOR - 0.3%)
- B takes out a (LIBOR + 0.6%) floating rate loan, and a swap where they pay 5.4% fixed and receive LIBOR (resulting in a fixed rate at 6%)
Now both parties improved the rate on their loans by 0.4%, and the bank that arranged the swap makes 0.1%.
*I added a spread to the floating leg to make the math more straightforward, in reality you would simply adjust the rate on the fixed leg.