Most production systems use a leader-based protocol, with Raft and Multi-Paxos being the two common choices. One node is elected leader. Clients send writes to the leader, the leader appends the write to its log and forwards it to the followers. Once a majority of nodes have stored the entry, the leader marks it committed and tells everyone. Because every commit requires a majority, no two conflicting values can both be committed.
The majority rule is the heart of it. With 5 nodes you need 3 to agree, so the system survives 2 failures. Any two majorities of 5 nodes must overlap in at least one node, and that overlap is what prevents split decisions. This is why consensus clusters almost always run an odd number of nodes: 3, 5, or 7.
When the leader crashes, followers stop hearing heartbeats, a timeout fires, and they hold an election to pick a new leader. The protocol uses term numbers or ballot numbers so that an old leader that wakes up cannot overwrite decisions made after it left. A node will only vote for a candidate whose log is at least as up to date as its own, which guarantees no committed entry is ever lost.
Newer protocols like EPaxos and Raft variants reduce the cost in different ways, for example by letting any node accept writes when operations do not conflict, or by batching many client requests into one round of agreement to raise throughput.