# How Gas Works

By [0xhubman.eth](https://paragraph.com/@0xhubman.eth) · 2024-11-19

---

Have you ever tried to submit a transaction on Ethereum mainnet and wondered "why is the gas so expensive"? If so, you've come to the right place. This post's focus is all on 'Gas' as it relates to blockchain transactions and how gas fees are calculated under the hood.

In its most basic form, gas is a unit of account that measure the computational effort required to perform specified actions on a blockchain. Gas is needed to perform transactions, regardless of the blockchain's consensus mechanism (i.e., Proof of Work, Proof of Stake, etc) or throughput ability. So as the name implies, gas used for blockchain transactions is similar in nature to how gasoline is used to power a car.

Gas is normally (but not always) denominated and paid for in a blockchain's native token, such as BTC for Bitcoin, ETH for Ethereum, MATIC for Polygon, AVAX for Avalanche, FTM for Fantom, etc. For the purposes of this post, we'll focus on Ethereum gas fees. To calculate gas fees for a transaction on Ethereum mainnet, there are specific inputs used for the calculation: gas units (limit), gas price (gwei), gwei converter, and the price of Ether. Below are additional details on each input.

*   **Gas Units (Limit)** - Typically, certain functions on the Ethereum blockchain require a certain amount of 'gas units'. For example, to transfer ETH between two wallet addresses, that typically requires 21,000 gas units. 21,000 is the limit for how many gas units could be used for this transaction.
    
*   **Gas Price (Gwei)** - Gas price is the amount of gwei you pay per gas unit. For reference, gwei is to Ethereum, as satoshis are to Bitcoin, as cents are to dollars. So if the gas limit is 21,000 to transfer ETH and the gas price is 60 gwei, you would perform the following calculation: 21,000 \* 60 = 1,260,000 gwei
    
*   **Gwei Converter** - this input converts the amount of gwei you pay per transaction into the equivalent amount of Ether that will be deducted from your wallet. The gwei converter is equal to 0.000000001 ETH. So continuing the calculation: 1,260,000 \* 0.000000001 = 0.00126 ETH. So you gas fee in terms of ETH is 0.00126 ETH.
    
*   **Price of Ether (USD)** - This step is optional, but it converts your gas fee into USD terms. Say the price of Ether is $1800 USD, so to finalize our calculation : 0.00126 \* 1800 = 2.268 USD.
    

In summation, It would will cost a user $2.268 (0.00126 ETH) to transfer ETH between 2 wallet addresses with the assumptions above. In reality, these inputs are constantly changing and most wallet browser extensions and mobile applications calculate these costs in near real-time as new blocks are validated on Ethereum and the inputs change. In addition, when interacting with smart contracts, gas fees are typically much more expensive since the smart contract is executing multiple functions within a single transaction and requires many more gas units (sometimes as high as multiple 1,000,000s of gas units).

Digging deeper for a moment, this is just how you calculate gas fees on Ethereum mainnet (L1). If you remember an earlier blog post , L2 rollups on Ethereum such as Optimism and Arbitrum have gained immense popularity due to sharing the security of Ethereum but having lower gas fees (relative to Ethereum mainnet). To calculate gas fees on L2s, you would take the above inputs and perform the calculation for both L1 (this is called the data security fee) and L2 (this is called the execution fee) and add them together. The calculations for determining the execution fee on L2s are constantly changing as new updates are deployed to these networks, but typically the execution fee is substantially cheaper than the data security fee.

If you would like to fall further down this rabbit hole, below are a few resources to continue your descent.

*   [Ethereum Foundation blog: Gas and Fees](https://ethereum.org/en/developers/docs/gas/#:~:text=and%20the%20EVM.-,What%20is%20gas%3F,each%20transaction%20requires%20a%20fee.)
    
*   [What is GAS (YouTube video)](https://www.youtube.com/watch?v=Yh8cHUB-KoU&ab_channel=Finematics)
    
*   [Gas (Ethereum) - Investopedia](https://www.investopedia.com/terms/g/gas-ethereum.asp)
    
*   [Extra Credit: Etherscan Transaction feed](https://etherscan.io/txs) - click on any transaction and see if you can identify the relevant inputs and back into the gas fee paid by the user!
    

Until next time!

---

*Originally published on [0xhubman.eth](https://paragraph.com/@0xhubman.eth/how-gas-works)*
