← Back to blogError detection

Parity Bit Tutorial: Single-Bit Error Detection

Derive even and odd parity with XOR, build a balanced generator and checker, quantify undetected errors, and understand what UART parity can—and cannot—prove.

DennyDenny
6 min read
Chalkboard feature illustration for “Parity Bit Tutorial: Single-Bit Error Detection”

TL;DR: A parity bit extends a data word so its total number of ones is even or odd. XOR implements both generation and checking. The resulting code detects every odd number of flipped bits—including every single-bit error—but every even-weight error pattern is invisible.

Parity is the smallest useful error-detecting code. It adds one bit, needs a reduction XOR, and gives a precise guarantee: changing an odd number of bits changes the word’s parity.

That guarantee is narrower than “the data is valid.” A clean check cannot distinguish an unchanged word from one in which two, four, or another even number of positions flipped. Professional use starts by stating that limit and deciding whether the residual undetected-error probability is acceptable.

Even and Odd Parity

For an mm-bit data word

D=Dm−1Dm−2…D1D0D=D_{m-1}D_{m-2}\ldots D_1D_0

define the reduction XOR:

XD=Dm−1⊕Dm−2⊕⋯⊕D0X_D=D_{m-1}\oplus D_{m-2}\oplus\cdots\oplus D_0

XD=1X_D=1 exactly when the data contains an odd number of ones.

For even parity, choose:

Peven=XDP_{\text{even}}=X_D

Then the XOR of all transmitted positions is zero:

Dm−1⊕⋯⊕D0⊕Peven=0D_{m-1}\oplus\cdots\oplus D_0\oplus P_{\text{even}}=0

For odd parity, invert that bit:

Podd=XD‾P_{\text{odd}}=\overline{X_D}

and the combined XOR is one. Neither convention is intrinsically stronger. Sender and receiver must use the same convention and agree on exactly which fields are covered.

Four-Bit Generator Table

D3D2D1D0D_3D_2D_1D_0Number of onesPevenP_{\text{even}}PoddP_{\text{odd}}
0000001
0001110
0011201
0111310
1111401

The omitted rows follow the same rule; the bit pattern’s numeric value is irrelevant. Only the number of ones modulo two matters.

This is addition over the two-element field:

1⊕1=0,1⊕1⊕1=11\oplus1=0,\qquad 1\oplus1\oplus1=1

Two flips cancel in the parity sum, which explains both the circuit and the limitation.

Building the Generator

Two-input XOR gates are associative:

(A⊕B)⊕C=A⊕(B⊕C)(A\oplus B)\oplus C=A\oplus(B\oplus C)

so several topologies implement the same Boolean function.

Linear chain

D7 ─┐
    XOR─┐
D6 ─┘  XOR─┐
D5 ─────┘  XOR─ ... ─ P

For mm inputs, a simple chain uses m−1m-1 two-input XOR operations and has up to m−1m-1 logical gate levels.

Balanced tree

D7 ─┐
    XOR─┐
D6 ─┘   │
        XOR─┐
D5 ─┐   │   │
    XOR─┘   │
D4 ─┘       │
            XOR─ P
D3 ─┐       │
    XOR─┐   │
D2 ─┘   │   │
        XOR─┘
D1 ─┐   │
    XOR─┘
D0 ─┘

For eight inputs, a balanced binary tree has three logical XOR levels. It usually offers less logic depth than a seven-level chain.

Do not attach a universal nanosecond value to either diagram. Actual delay depends on the gate family or FPGA mapping, routing, fan-out, supply, temperature, and input arrival times. If a wide parity tree lies on a timed path, verify it with the target implementation’s timing tools.

The Receiver’s Checker

For received data D′D' and received even-parity bit P′P':

S=Dm−1′⊕⋯⊕D0′⊕P′S=D'_{m-1}\oplus\cdots\oplus D'_0\oplus P'

SS is often called a parity syndrome or parity error indication:

  • S=0S=0: no odd-weight error was detected;
  • S=1S=1: an odd number of covered positions differs from what was sent.

The checker cannot identify a position and therefore cannot correct the word. Its output should feed a defined response: mark the word invalid, raise a status bit, increment a diagnostic counter, or request retransmission through a higher-level protocol.

For odd parity, invert the pass/fail interpretation or compare the combined XOR with one.

Worked 8-Bit Example

Let the data byte be:

D = 10110100

It contains four ones, so even parity appends P=0:

transmitted codeword = 10110100 0

Clean reception

The XOR of all nine positions is 0, so the checker reports no detected parity error.

One flipped position

If D3 changes from 0 to 1:

received = 10111100 0

The combined XOR is 1. The receiver knows the codeword is corrupt, but not whether the fault is in D3, another data position, or P.

Two flipped positions

If D3 changes 0→1 and D5 changes 1→0:

received = 10011100 0

The combined XOR returns to 0. The corrupted word passes the parity check because the error pattern has even weight.

What Parity Guarantees

A single parity bit creates a code with minimum Hamming distance 2. It detects every error pattern of weight 1, and more generally:

Number of flipped covered positionsDetected?
1always
2never
3always
4never
any odd numberalways
any positive even numbernever

“Never” here means parity alone has no way to distinguish that error pattern from a valid codeword. Another layer—such as a CRC, sequence number, framing rule, or application constraint—might still expose it.

Parity does not:

  • locate the changed bit;
  • correct data;
  • detect every burst;
  • authenticate a message;
  • prove that a physical link is healthy;
  • protect fields excluded from its coverage.

An attacker can deliberately modify data and recompute parity. Use a cryptographic message-authentication mechanism when malicious tampering is in scope.

Quantifying Random Undetected Errors

Assume a codeword contains nn covered positions and each flips independently with probability pp. The probability of an even number of flips is:

Peven=1+(1−2p)n2P_{\text{even}}=\frac{1+(1-2p)^n}{2}

That includes the no-error event, whose probability is (1−p)n(1-p)^n. Therefore the probability of an undetected corrupted codeword is:

Pundetected=1+(1−2p)n2−(1−p)nP_{\text{undetected}} = \frac{1+(1-2p)^n}{2}-(1-p)^n

For small pp, the dominant term is:

Pundetected≈(n2)p2P_{\text{undetected}}\approx {n\choose2}p^2

An 8-bit data word plus parity has n=9n=9, so the first-order undetected contribution is approximately 36p236p^2, not 28p228p^2; the parity position can fail too.

This model assumes independent, identically distributed bit flips. Real channels can have correlated noise and bursts, so measured or specified channel behavior should drive the code choice.

UART Parity in Context

A configurable asynchronous serial frame is commonly described with strings such as:

  • 8N1: 8 data bits, no parity, 1 stop bit;
  • 8E1: 8 data bits, even parity, 1 stop bit;
  • 8O1: 8 data bits, odd parity, 1 stop bit.

UART framing and the RS-232 electrical interface are related in many systems but are not the same specification. The UART defines how characters are serialized and checked; an RS-232 transceiver defines voltage-level signaling for an interface.

A receiver that detects the wrong parity normally reports a parity error. A framing error is a different condition, commonly associated with an invalid stop bit. Microcontroller USARTs often expose separate status flags for these events.

Whether the receiver discards the character, delivers it with an error flag, or triggers an interrupt is implementation and software policy. Do not assume parity automatically requests retransmission; a protocol above the UART must define that behavior.

Parity, Hamming Codes, and CRCs

PropertySingle parityHamming(7,4) decoderCRC
core operationXOR reductionparity-check syndromepolynomial remainder over GF(2)
corrects errorsnoone bit, under its error modelnormally no
detects all one-bit errorsyesyesdepends on polynomial; standard choices generally do
even-weight error visibilitynone from parity alonecode- and decoder-dependentpolynomial- and message-length-dependent
typical rolelightweight per-word checkforward correction for small blocksstrong frame/block detection

Extended Hamming adds overall parity to support single-error correction and double-error detection under the assumed error limit. CRC strength depends on the generator polynomial and protected length; it should not be summarized as “catches all bursts” without those parameters.

Build It in DigiSim

Use the 8-bit serial transmitter/receiver template or a fresh canvas:

  1. Place eight data switches.
  2. Build a balanced XOR tree for even parity.
  3. Append P to the data word.
  4. Build a second XOR tree across all nine received positions.
  5. Add one fault-injection XOR per transmitted position.
  6. Verify every single-position fault produces S=1.
  7. Inject selected two-position faults and verify they pass undetected.
  8. Change to odd parity by inverting P and update the expected check value.

Also test transitions, not only static words. Unequal path delays can produce a temporary parity pulse while several data inputs change. Register the complete data word before checking it, or sample the syndrome only when the protocol says the word is stable.

When single-bit correction is the next requirement, continue with Hamming(7,4). Its several parity checks turn one error indication into a syndrome that identifies the position.

Reference

Apply the concept in a simulator model.