What is consensus in a blockchain?

In plain words
Consensus is the set of rules by which the participants in a network agree on which record counts as correct and which block to add next. A copy of the blockchain ledger is held by many participants at once, and there is no boss to decide for everyone. So the network needs a fair procedure that lets those participants reach a common agreement without a trusted center. That procedure is what people call a consensus mechanism.
Picture a large group with no leader that has to decide what to write into a shared record. They need an honest way to reach agreement, one that is very hard for any single participant to force through. A consensus mechanism is exactly that, only for a network of computers.
Why does it matter to you? The consensus mechanism shapes how secure the network is, how quickly transfers go through, and how much electricity it uses. It is also the reason some coins are mined while others are staked. Mining means earning the right to a new block through a computer’s work. Staking means putting up a deposit of your own coins. Both are covered in detail in miners and validators.
Deeper
The two best-known approaches
The first approach is called Proof of Work. Its participants are called miners. They compete to be the first to solve a hard computational puzzle. Whoever solves it first adds the new block and gets a reward in coins for it. The approach is robust, but it burns a lot of electricity. This is how the Bitcoin network works.
The second approach is called Proof of Stake. Instead of computing, a participant called a validator freezes a deposit of their own coins in the network and, under the network’s rules, gets a turn now and then to propose a new block. If they try to cheat, part of their deposit is burned under the network’s rules. This penalty is called slashing. This approach usually needs far less energy. The Ethereum network switched from Proof of Work to Proof of Stake on 15 September 2022, an event known as The Merge, and the network’s energy use dropped by roughly 99.95%1.
Beyond Proof of Work and Proof of Stake
These are not the only options, and it is worth knowing that, because beginners are often told it is only ever mining or staking. The XRP Ledger, for example, uses neither. There, trusted validating servers agree on transfers. Each of them goes by its own list of servers it trusts; such a list is called a Unique Node List. Over several rounds of cross-checking they arrive at a common decision, with no competition and no deposit2. Other mechanisms exist too, but they all share one task, to agree on a single history of records without any central authority.
Why consensus affects you
The consensus mechanism shapes the speed of transfers, the size of the fees, the electricity a network uses, and exactly how a coin is protected against forgery. It is one of the first things worth looking at in any network’s description.