The “out of gas” error occurs when all the gas you allotted for the transaction is consumed before the transaction could complete. During the transaction mining process, a portion of the gas is consumed for each operation that is executed on the Ethereum Virtual Machine (EVM) until the transaction is completed or until the amount of gas consumed reaches the gas limit.
The gas limit is the maximum amount of gas you are willing to consume. You can relate the gas limit to putting out a fire with water from a hydrant. If you do not have a large enough water supply, you may run out of water before you can extinguish the fire. As such, you will want to ensure that you include a gas limit high enough to complete your transaction.