What are gas and transaction fees, who pays them, and why?
Gas measures the computational work a transaction requires; the person initiating the transaction pays a fee (gas used times gas price) to the block producer as payment for processing it.
Every operation a transaction performs costs a certain amount of gas, a unit of computational effort — a simple transfer is cheap, a complex smart-contract call costs far more. The transaction fee is roughly gas used × gas price. The initiator of the transaction pays it, and it goes to the miner or validator who includes the transaction in a block. The fee exists to do two jobs: compensate node operators for spending real resources, and ration limited block space — when many people compete to get into a block, they bid gas prices up, so fees rise with demand. You can set a gas limit to cap how much computation you will pay for, protecting you from a runaway cost. (Some networks, such as Ethereum under its EIP-1559 fee model, additionally burn part of the fee, permanently removing it from circulation, and pay the rest as a tip to the block producer.)
Go deeper:
Gas and fees — ethereum.org — how gas measures computation, how fees are set, and the EIP-1559 base-fee burn.