A parity check detects errors by adding a single extra bit (the parity bit) to each byte so that the total number of 1s in the byte follows an agreed pattern.
The sender and receiver agree in advance whether they will use even parity or odd parity:
- Even parity: the total number of 1s in the byte (including the parity bit) must be even.
- Odd parity: the total number of 1s in the byte (including the parity bit) must be odd.
Setting the parity bit
To set the parity bit, the sender:
- Counts the 1s in the 7 data bits.
- If the count already matches the agreed parity, sets the parity bit to 0.
- If the count is the wrong parity, sets the parity bit to 1 to flip the total.
Example — The 7 data bits 1011010 are about to be sent with even parity. What is the parity bit?
- Count the 1s in the data bits: 4 (positions 1, 3, 4 and 6).
- 4 is already even, so the parity bit is set to 0 to keep the total even.
- Final 8-bit byte: 0 1011010.
Example — The 7 data bits 1011010 are about to be sent with odd parity. What is the parity bit?
- Count the 1s in the data bits: 4.
- 4 is even, so the parity bit must be 1 to make the total (5) odd.
- Final 8-bit byte: 1 1011010.
How the receiver detects an error
The receiver:
- Counts the 1s in every received byte.
- Checks whether the count matches the agreed parity.
- If yes, no error has been detected.
- If no, an error has occurred (and the data should be discarded or re-sent).
Example — A receiver expects odd parity and receives the byte 01101001. Has an error occurred?
- Count the 1s: positions 2, 3, 5 and 8 are 1, giving 4 ones.
- 4 is even, but odd parity was expected.
- An error has occurred.
Limitations of a single parity bit
Parity checks are cheap and quick but they cannot detect every error:
- Two bits flipped in the same byte cancel each other out and the parity still matches.
- A whole even-numbered group of bit flips also leaves the parity unchanged.
- Bit transposition (two bits swapping positions) does not change the parity at all.
- The parity check tells you whether an error has happened, but not which bit is wrong.
For better protection, a parity byte (also called a parity block) is used.