Decentralized networks require a method to achieve consensus, or agreement, among a majority of participants in the network about the validity of transactions without those participants necessarily knowing or trusting each other. Nakamoto consensus is the algorithm proposed by Satoshi Nakamoto to achieve this trustless consensus among participants in the Bitcoin network.
Critical to Nakamoto consensus is the idea of Proof of Work (PoW). Bitcoin's PoW protocol creates an economic disincentive (i.e. cost) for spamming or attacking the Bitcoin network by making it expensive to mine Bitcoin. This cost is due to the "lottery" system by which Bitcoin miners propose new blocks and earn block rewards.
All of the active miners in the network are continuously using electricity to perform computations with the hope of being the first miner to find the nonce that solves a cryptographic puzzle. The probability of any single miner finding a given nonce first is equal to the percentage of the total network mining power - (also called "hash power") - that they are contributing. For example, a miner who has 10% of the total network hash power has a 10% chance of being first to find a nonce.
The reason that being first to find the nonce is important is because finding the nonce gives the miner the chance to propose a new block to be added to the blockchain. The block is then propagated by the miner to the other miners across the network who check that all of the transactions in the block are valid. If the majority of miners agree that the block is valid, it is added to the blockchain and the miners continue building on that chain by adding future blocks to the end of it. Contained within each block is one extra transaction, called the block reward, which gives newly minted coins and transaction fees to the block proposer. The block reward is the only way for miners to directly profit from mining.
This block selection process prevents attacks and spam by making it economically wasteful for the malicious actor unless said actor controls a majority of the network's hash power. In other words, an attacker who controls 49% of the network's hash power can be dishonest by including invalid transactions such as double spend transactions in the blocks they propose, but over time the 51% of miners who remain honest will continue adding blocks to the blockchain proposed by other honest miners, while leaving out all of the blocks proposed by the attacker. As a result, the attacker's invalid transactions and block rewards won't be included in the longest chain with the greatest proof of work, so the entirety of the cost of electricity to mine during that time will be a loss.
On the other hand, if a malicious actor does control 51% or more of the total network hash power, they will be able to mine the longest chain with the greatest accumulated proof of work, allowing them to keep the block rewards and include invalid transactions. This is called a 51% attack. Apart from the cost of a failed attempt at a 51% attack, the other disincentive for miners to make this attempt is that it would cause the network's value to crash as users realize that invalid transactions have been or can be included. That means that the attacker would spend a lot of money on electricity in order to control the network, while simultaneously devaluing the network. Therefore, the most logical reason to attempt a 51% attack is not to control the blockchain for personal enrichment, but rather to destroy the blockchain network entirely.
In summary, Nakamoto consensus incorporates proof of work along with a "lottery" block selection process in order to make it costly to mine Bitcoin and to disincentivize spam and attacks on the network.
Andreas M. Antonopoulos: "Consensus Algorithms, Blockchain Technology and Bitcoin"
July 10, 2015
Bitcoin: A Peer-to-Peer Electronic Cash System
Let's take a crack at understanding distributed "consensus"
Nakamoto Consensus - nakamo.to - Medium