Ethereum implements a runtime environment on the blockchain, called the Ethernet Virtual Machine EVM.
Every node that participates in the network runs runs the EVM as part of the block validation protocol. They validate each transaction covered in the block and run the exchange-triggered code in the EVM. Each full node in the network performs the same calculations and stores the same values. The fact that contract execution is repeated multiple times across all nodes has to make contract execution expensive to consume, so it also drives everyone to not put any computation that can be performed off-chain onto the blockchain.
For each executed command there is a specific consumption, counted in units of Gas. Each command that a contract can utilize will have a corresponding Gas value.