What Is Gas Limit?

Updated: March 2026|5 min read read

Gas limit is the maximum amount of gas units a user is willing to spend on a blockchain transaction. It acts as a safety cap that prevents runaway costs from complex or buggy smart contract interactions. Setting the gas limit correctly is important: too low and your transaction fails (while still consuming gas), too high and you reserve more resources than needed, though unused gas is refunded.

What Is Gas Limit?

Gas limit defines the maximum number of gas units a transaction can consume. Each EVM operation has a fixed gas cost: a simple ETH transfer always costs 21,000 gas, while a complex DeFi swap might consume 150,000-300,000 gas. The gas limit ensures that if a smart contract has an infinite loop or unexpected behavior, it will terminate when the gas limit is reached rather than running indefinitely and draining your wallet.

How Gas Limit Works

When you submit a transaction, your wallet estimates the gas needed and suggests a gas limit, typically with a small buffer above the estimate. The total maximum fee you could pay is gas limit multiplied by gas price. Validators execute your transaction and charge only for the gas actually used. The transaction is included in a block as long as the total gas of all transactions does not exceed the block gas limit, which caps the total computation per block.

Setting the Right Gas Limit

Most wallets automatically estimate gas limits accurately. For standard transfers, 21,000 is always sufficient. For token transfers, 65,000 is typical. Complex DeFi interactions may need 200,000-500,000. When interacting with new or unverified contracts, increase the suggested limit by 20-30% as a safety margin. Never set an arbitrarily high gas limit thinking you will be charged more, as you only pay for gas actually consumed.

Common Gas Limit Issues

The most common issue is the out-of-gas error from setting the limit too low, especially on complex transactions. Some smart contracts have dynamic gas requirements that depend on network state, making static estimates unreliable. Block gas limits also cap how much total computation can fit in a single block, which during congestion means transactions with lower gas prices may be delayed even with correct gas limits. Using gas estimation APIs from providers like Alchemy can help avoid these issues.

Frequently Asked Questions

What happens if my gas limit is too low?

Your transaction will fail with an 'out of gas' error. The blockchain still charges you for the gas consumed up to the point of failure because the computational work was performed. The state changes are reverted, but the fee is not refunded. Always use the recommended gas limit or slightly above.

Do I get refunded for unused gas?

Yes. If your transaction uses less gas than your gas limit, the unused portion is refunded to your wallet. For example, if you set a gas limit of 100,000 but the transaction only uses 60,000, you are refunded for the 40,000 unused gas units. This is why setting a higher gas limit than necessary is safer than setting it too low.

Related Articles