Every operation on a smart-contract chain costs gas. You set a ceiling when you sign. If execution finishes below it you pay only for what was used; if it hits the ceiling, the transaction reverts and you still pay for everything consumed.
Wallets estimate the limit by simulating, but simulation can be wrong when state changes between estimate and execution, which is common in fast markets and complex DeFi routes.
Example: a simple transfer uses 21,000 gas. A swap through several pools might use 300,000. Setting a limit of 200,000 on that swap produces a failed-transaction that costs the full 200,000 in gas and delivers nothing.
Related: gas-fee, failed-transaction, base-fee, blockspace