Gas is a term used to refer to the amount of computational work required to validate a transaction. This work is put in by the nodes who are helping maintain the network by dedicating computational power, and in return, they are paid a fee with every transaction. This fee is based on a ‘gas price’ and is denoted in terms of Ether (ETH). The fee for each transaction is many orders smaller than one whole Ether, and is referred to in terms of Gwei. One Gwei amounts to 10^(-9) Ether.
i.e. 1 Gwei = 0.000000001 Ether
A good way to think about gas is to picture it as fuel. Gas is the fuel required by computers which have to exert energy and other resources to validate a transaction. The fact that every transaction on the blockchain costs something to pass, deters any potential bad actors from abusing the system by overloading it with large numbers of malicious transactions or spam.
When a transaction is submitted to the blockchain, the ‘gas limit’ can also be specified. This establishes the maximum fee that one is ready to pay to make the transaction go through. When a smart contract is being published, the gas is calculated per every computational step written in the code. A gas limit, then, is of significant advantage as it prevents the system from getting stuck in any sort of unintended loops inside smart contracts and wasting the network’s computational resources.