Digital Logic
What is a parity bit?
A parity bit is one extra bit sent with a group of data bits, chosen so that the total number of 1s is even (or, by agreement, odd). The receiver counts the 1s again. If the count comes out odd, at least one bit flipped on the way. It's the simplest error check there is, and it's one XOR gate per bit.
Making the parity bit
Take three data bits, 1 0 1. They hold two 1s, already even, so the parity bit is 0. For 1 0 0, with one 1, the parity bit is 1, making two. The sender sends four bits: the data plus parity.
The parity bit is the XOR of the data bits. XOR gives 1 when its inputs differ, and a chain of XORs gives 1 when an odd number of its inputs are 1:
Checking it
The receiver XORs all four bits, parity included. If nothing flipped, the count is even and the answer is 0. If one bit flipped, any bit at all, the count is odd and the answer is 1: ERROR.
A checker for n bits needs n − 1 two-input XORs, each folding one more bit into the running answer. For four bits, three XORs.
Live experiment
Zap a wire
Three data bits and the parity bit that makes their 1s even travel four wires to a checker, a chain of three XORs. Zap a wire and its bit flips on the way: one zap makes the count odd and ERROR lights; a second zap makes it even again and nothing looks wrong.
“Parity” is lesson 4 of 6 in Nand Narrows, Digital Logic World 2. Free with an account. Lessons unlock in order, so you’ll do the 10 before it first.
What it can't do
Parity also can't say which bit flipped. Any single error looks the same, an odd count, so the receiver can only reject the data and ask for it again. That's fine when errors are rare and independent, one now and then. A scratch or a burst of radio noise that flips several neighbouring bits needs stronger codes.
Where you'll meet it
Serial ports can add a parity bit to each character: a setting written 8E1 means 8 data bits, even parity and 1 stop bit. Early PC memory stored a ninth bit with every byte for parity. Richard Hamming went further at Bell Labs in 1950: with several parity bits, each checking a different overlapping group, the pattern of failed checks points to the flipped bit, so it can be corrected. ECC memory in servers, QR codes and spacecraft links all build on that idea. A checksum on a file or a packet is the same idea, scaled up.
Free lesson
Now build it yourself
Each lesson comes in three short parts: see the idea, try it on a live board, then build it yourself, with quick checks as you go.
“Parity” is lesson 4 of 6 in Nand Narrows, Digital Logic World 2. Free with an account. Lessons unlock in order, so you’ll do the 10 before it first.
Or start from the very first lesson, no account neededPractice questions
Three quick questions from the lessons. Pick an answer to check it.
Show the answer
Answer: ERROR: four bits with three 1s, odd. The sender made the count even. A flipped bit makes it odd, and the XOR of all four is 1. It can't tell which bit, only that one did.
- Why not “Fine”? The four bits now hold three 1s, an odd count, which even parity says can't happen without an error.
- Why not “Nothing”? The checker does respond: the XOR of all four bits is 1, which lights ERROR.
- Why not “Which bit flipped”? One parity bit only says something went wrong, not where: any single flip makes the count odd in the same way.
Show the answer
Answer: Misses it: two flips keep the count even. Each flip changes the count by one, so two flips change it by two, and even stays even. Parity only catches odd numbers of errors.
- Why not “Breaks”? Nothing breaks: the checker works fine and reports even, which is exactly why two flips slip through.
- Why not “Catches it”? Two flips change the count of 1s by two, so an even count stays even and the check passes.
- Why not “Says which bits”? Parity can't point to any bit, let alone two. It only knows whether the count is odd.
Show the answer
Answer: An odd number of inputs are 1. XOR chains count ones, odd or even.
- Why not “No inputs are 1”? No 1s at all is an even count, zero, so the chain gives 0.
- Why not “An even number are 1”? An even number of 1s cancels out in pairs, so the chain gives 0. That's what makes it a parity checker.
- Why not “All inputs are 1”? All inputs at 1 gives 1 only when there's an odd number of them. With four 1s, the chain gives 0.
“Parity” is lesson 4 of 6 in Nand Narrows, Digital Logic World 2. Free with an account. Lessons unlock in order, so you’ll do the 10 before it first.
Questions people ask
What is the difference between even and odd parity?
With even parity, the parity bit is chosen so the total number of 1s, data and parity together, is even. With odd parity it's chosen to make the total odd. Both catch any single flipped bit; sender and receiver just have to agree.
Can a parity bit correct errors?
No. One parity bit shows that an odd number of bits flipped, but not which ones, so the receiver can only ask for the data again. Correcting errors takes more check bits, as in a Hamming code.
Where are parity bits used?
In serial links like a UART, which can add a parity bit to each character, in older memory modules, and as the building block of error-correcting codes in ECC memory, storage and radio links.
Related topics
- Binary numbers explainedPlaces worth 1, 2, 4 and 8: add up the bits that are on, and four wires count to 15.
- Logic gates explainedAND, OR, NOT, XOR and their bubbled twins: each one's rule is a truth table.
- What is Gray code, and why do encoders use it?A count where only one bit changes per step, and why encoders depend on it.
- Half adder vs full adderA half adder adds two bits; a full adder adds the carry too, so they chain.