On blockchains like Ethereum, smart contracts are a piece of code running on top of the blockchain protocols that where the rules of a transaction are embedded into the code and automatically enforced once all parties to the smart contract meet the pre-defined rules. Smart contracts can radically reduce transaction costs of reaching an agreement, formalization, and enforcement of relationships between people, institutions and the assets they own, by standardizing transaction rules. The transaction rulesets (agreement) of the smart contract define the conditions – rights and obligations – to which parties to a smart contract consent. They are often predefined, and agreement is reached by simple opt-in actions. They are formalized in digital form, in machine-readable code (formalization). These rights and obligations established in the smart contract can now be automatically executed by a computer or a network of computers as soon as the parties have come to an agreement and met the conditions of the agreement (enforcement). This auto enforceable code of the blockchain layer, as well as the smart contract layer, radically reduces transaction costs, replacing traditional middle men with machine consensus.
Source:
https://blockchainhub.net/blog/infographics/smart-contracts-explained/