Skill 5.2.1
Determine the gas cost of common EVM operations
Key Concepts
Every transaction pays intrinsic gas: 21,000 base, plus 32,000 for contract creation, plus calldata at 4 gas per zero byte and 16 gas per non-zero byte (since the Pectra upgrade, transactions that are mostly data pay a higher floor rate). A plain ether transfer to an externally owned account therefore costs exactly 21,000 gas.
Storage dominates contract costs. Under EIP-2929, the first access to a storage slot in a transaction is cold and costs 2,100 gas extra; later accesses are warm. SLOAD costs 2,100 cold or 100 warm. SSTORE costs 20,000 to set a zero slot to a non-zero value and 2,900 to change a non-zero value (plus 2,100 if cold). Clearing a slot to zero earns a refund, but refunds are capped at one fifth of the transaction's gas used (EIP-3529).
Other costs: arithmetic is 3 to 5 gas per operation, memory grows quadratically but is cheap for small sizes, a log costs 375 gas plus 375 per topic plus 8 per byte of data, calling a cold address costs 2,600, and deploying code costs 200 gas per byte stored.