Consensus Mechanisms
Consensus mechanisms are the rules that all nodes follow to agree on which transactions are valid and which block to add next. This is a foundational concept in decentralized application development that professional developers rely on daily. The explanations below are written to be beginner-friendly while covering the depth and nuance that comes from real-world Blockchain/Web3 experience. Take your time with each section and practice the examples
30 min•By Priygop Team•Last updated: Feb 2026
What is Consensus?
Since there's no central authority in a blockchain, all nodes must agree on the state of the ledger. Consensus mechanisms are the protocols that achieve this agreement. The two most important are Proof of Work (PoW) used by Bitcoin, and Proof of Stake (PoS) used by Ethereum (since 2022).
Proof of Work vs Proof of Stake
- Proof of Work (PoW) — Miners compete to solve a math puzzle. Winner adds the block and earns a reward. Used by Bitcoin
- Proof of Stake (PoS) — Validators stake (lock up) cryptocurrency as collateral. Chosen randomly to validate. Used by Ethereum
- PoW Energy — Very energy-intensive (Bitcoin uses ~150 TWh/year, similar to Argentina)
- PoS Energy — 99.95% more energy-efficient than PoW
- 51% Attack — If one entity controls 51%+ of mining power (PoW) or stake (PoS), they could manipulate the chain
- Block Reward — Miners/validators earn cryptocurrency for successfully adding blocks
Proof of Work Simulation
Example
// Simplified Proof of Work simulation
// Miners must find a number (nonce) that makes the hash start with zeros
function simpleHash(data) {
// Simplified hash (not real SHA-256)
let hash = 5381;
for (let i = 0; i < data.length; i++) {
hash = ((hash << 5) + hash) + data.charCodeAt(i);
hash = hash & hash; // Convert to 32-bit integer
}
return Math.abs(hash).toString(16).padStart(8, "0");
}
function mineBlock(data, difficulty) {
let nonce = 0;
const target = "0".repeat(difficulty); // Hash must start with this many zeros
console.log(`Mining block with difficulty ${difficulty}...`);
while (true) {
const hash = simpleHash(data + nonce);
if (hash.startsWith(target)) {
console.log(`✓ Block mined! Nonce: ${nonce}, Hash: ${hash}`);
return { nonce, hash };
}
nonce++;
}
}
// Mine a block (difficulty 2 = hash must start with "00")
const result = mineBlock("Alice→Bob:1BTC", 2);
console.log("Attempts needed:", result.nonce);
console.log("This is why mining takes energy — it's trial and error!");