Gas fees are a way to incentivize validators to validate one of our transactions (sending tokens) or interaction with a smart contract. In these cases, the costs are not fixed but dynamic and variable in
function of the use of the blockchain at that moment (we speak of a congested network, if there are many transactions in the queue).
The fees we give to the validators are paid with the coin of the network we are using (ETH for Ethereum, SOL for Solana, AVAX for Avalanche, BTC for Bitcoin, etc), the unit of measure with which we calculate how much we should pay is called gas.
Each transaction has a base cost of 21000 (gas), plus any extra costs to interact with a contract. However, this is only one of the two values that can be set and is called "gas limit". The other variable value is the price, i.e. how much we are willing to pay for a single unit of gas. The gas value is expressed in gwei; each gwei equals one-billionth of one of these coins. So, on the Ethereum network, 1 gwei is worth 0.000000001 ETH.

So we can define:
-Gas limit: The maximum amount of gas we would like to use
-Gas price: the price we are willing to pay to have priority on the next block in the chain
By researching the gas tracker of the blockchain we are using, we can know the average cost of gas at that moment.
Usually the Gas Trackr (Etherscan) offer us three "different" costs, with three orders of priority: fast transaction (for example 17 gwei, so as to increase the chances that the transaction will be processed in the next blocks), medium (14 gwei) or slow (14 gwei or less).

The gas limit is the maximum quantity I am willing to spend (it is not certain that I will spend it all), while the gas price is the actual expenditure. If the average commissions on the Ethereum network were currently 30 gwei (0.000000030 ETH), it would mean that I would have to pay, in terms of ETH:
21000*0.000000030 = 0.00063 ETH
Before exchanging tokens in an AMM, the smart contract will need approval in order to withdraw funds from our wallet. We should give this approval to it and during the procedure we will have to choose how many erc20 tokens the smart contract will be able to withdraw from our wallet. Basically, the contract asks us how many tokens it will be able to spend. I can set a low number and not the maximum. After setting this value, click on continue and we will find ourselves in the commission customization screen. By clicking on "market/advanced" of Metamask, I can modify:
-Max Base Fee: this is the maximum quantity that we would be willing to pay (calculated by making the average base fee + priority fee) This is the real value considered by the Ethereum blockchain as the minimum quantity of gas necessary to execute a transaction in the next block. If this figure will be lower compared to the average price seen on the gas tracker, the transaction will not be processed until the average price of the latter drops to that threshold.
-Priority Fee: This is what we are paying to the validators.
-Gas Limit (below): this value should not be modified because it refers to the amount of work required to complete an operation and is estimated directly from the contract or the tx you are carrying out.

You should first evaluate the average costs of the network and then set a priority fee that is high but lower than the max base fee, so as to give the operation some margin so that it is certainly finalized.
Are you interested in ways to earn crypto bonus? Check it out here: Some Sites To Earn Crypto Bonus (Old & New)