How swaps work
Most DEXs use automated market makers: liquidity providers deposit pairs of tokens into a pool, and a formula sets the price based on the balance in the pool. You pay a small swap fee to the liquidity providers plus the network's gas fee.
DEX or CEX
On a DEX you keep custody of your coins and can trade any token someone has listed, without signing up. On a centralized exchange you get fiat deposits, customer support and usually deeper liquidity for large coins, but the exchange holds your funds.