How RAID Parity Actually Works

RAID parity is a mathematical technique that allows an array to survive drive failures without losing data. The core operation is XOR (exclusive OR): a bitwise function that compares bits from multiple data blocks and produces a parity block. If any one input is lost, it can be recalculated from the remaining inputs and the parity. RAID 5 uses single parity (one drive failure tolerance). RAID 6 uses dual parity (two drive failure tolerance). The math is straightforward, but the implementation details of stripe layout, parity distribution, and write handling determine how the array performs and how it fails.
XOR Parity: The Math Behind RAID 5
XOR operates on individual bits. The rule: if the input bits are the same, the output is 0. If they differ, the output is 1.
| Bit A | Bit B | A XOR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
XOR is associative and commutative, which means it scales to any number of inputs: A XOR B XOR C XOR D = P. More importantly, XOR is its own inverse. If you lose any single value, XORing the remaining values (including the parity) reproduces the missing one.
In a four-drive RAID 5 array, each stripe has three data blocks (D1, D2, D3) and one parity block (P). The parity block stores D1 XOR D2 XOR D3. If drive 2 fails, the controller reconstructs D2 by computing D1 XOR D3 XOR P. This calculation happens for every stripe across the entire array during a rebuild or during degraded-mode reads.
A concrete example with bytes: if D1 = 10110010, D2 = 01101001, and D3 = 11001100, then P = 10110010 XOR 01101001 XOR 11001100 = 00010111. If D2 is lost, D1 XOR D3 XOR P = 10110010 XOR 11001100 XOR 00010111 = 01101001. The original D2 is recovered exactly.
Distributed Parity vs Dedicated Parity
RAID 3 and RAID 4 use a dedicated parity drive: one specific drive stores all parity blocks. Every write to any data drive requires a corresponding parity update on the parity drive. This creates a bottleneck: the parity drive handles write I/O for every data operation across the array, limiting write throughput.
RAID 5 solves this by distributing parity blocks across all drives in a rotating pattern. In a four-drive array:
| Stripe | Drive 0 | Drive 1 | Drive 2 | Drive 3 |
|---|---|---|---|---|
| 0 | D0 | D1 | D2 | P |
| 1 | D3 | D4 | P | D5 |
| 2 | D6 | P | D7 | D8 |
| 3 | P | D9 | D10 | D11 |
The parity block rotates to a different drive in each stripe (left-symmetric layout shown above). This distributes write I/O evenly: no single drive is a bottleneck. The specific rotation pattern (left-symmetric, left-asymmetric, right-symmetric, right-asymmetric) varies by controller manufacturer and affects the order in which data and parity are laid out. During recovery, knowing the exact layout algorithm is necessary to reassemble the array correctly.
RAID 6 Dual Parity
RAID 6 adds a second parity block to each stripe, labeled Q. The P block is calculated with standard XOR, identical to RAID 5. The Q block uses a different mathematical function based on Galois field arithmetic (GF(2^8)). Each data block is multiplied by a different coefficient in the Galois field before being XORed together. This makes P and Q mathematically independent: two simultaneous unknowns (two failed drives) can be solved using two independent equations.
The practical effect: RAID 6 tolerates two simultaneous drive failures. This matters increasingly with large-capacity drives (8 TB, 16 TB, 20 TB+) because the probability of an unrecoverable read error (URE) during rebuild is high enough that a second failure during a RAID 5 rebuild is a realistic scenario, not a theoretical one.
RAID 6 requires a minimum of four drives (two data, two parity). Usable capacity is (N-2) drives. Write performance is lower than RAID 5 because every data write requires updating both P and Q parity blocks. Hardware RAID controllers with dedicated XOR engines and battery-backed cache mitigate this penalty.
Stripe Size, Chunk Size, and Layout
The chunk size (also called strip size) is the amount of contiguous data written to a single drive before moving to the next drive in the array. Common values are 64 KB, 128 KB, 256 KB, and 512 KB. A stripe is the set of chunks across all drives at the same address offset, including the parity chunk(s).
Chunk size affects performance. Small chunks (64 KB) spread each I/O across more drives, improving throughput for large sequential reads. Large chunks (512 KB) keep individual I/O operations on a single drive, improving random I/O performance by reducing cross-drive coordination.
During RAID recovery, the chunk size must be known exactly. If a recovery tool assembles the array with the wrong chunk size, the data interleaving is incorrect and the resulting image will be garbled. PC-3000 RAID analyzes the raw data on each drive to detect the correct chunk size, parity rotation direction, and drive order automatically when the RAID controller metadata is damaged or unavailable.
The RAID Write Penalty
Every data write in a parity RAID requires reading the old data, reading the old parity, calculating new parity, writing new data, and writing new parity. This is the read-modify-write cycle. RAID 5 has a write penalty of 4 (four I/O operations per logical write). RAID 6 has a write penalty of 6 (two parity blocks to update instead of one).
| RAID Level | Write Penalty | Drive Failures Tolerated | Usable Capacity |
|---|---|---|---|
| RAID 0 | 1 | 0 | N drives |
| RAID 1 | 2 | 1 (per mirror pair) | N/2 drives |
| RAID 5 | 4 | 1 | N-1 drives |
| RAID 6 | 6 | 2 | N-2 drives |
| RAID 10 | 2 | 1 per mirror pair | N/2 drives |
Hardware RAID controllers with battery-backed write cache (BBU/BBM) absorb the write penalty by caching writes in DRAM and flushing them to drives in optimized batches. If the BBU fails or the cache policy is set to write-through, the full write penalty applies and write latency increases by 5-10x. Dell PERC controllers, HP SmartArray, and LSI MegaRAID all implement this caching strategy.
Parity protects against drive failure, not data corruption.
RAID parity recalculates missing data from failed drives, but it does not detect or correct silent data corruption. If a drive returns incorrect data without reporting an error (a bit flip in DRAM, a firmware bug, or a media defect below the drive's error threshold), the parity system will incorporate the corrupted data into parity calculations without warning. Only checksumming filesystems like ZFS or Btrfs detect this type of corruption.
Frequently Asked Questions
How does RAID 5 reconstruct data from a failed drive?
The controller reads data blocks and parity blocks from the surviving drives for each stripe. Because XOR is reversible, any single missing value can be recalculated by XORing the remaining values. This works for one failed drive; a second failure during rebuild causes data loss.
What is the difference between RAID 5 and RAID 6?
RAID 5 uses one parity block per stripe (XOR) and survives one drive failure. RAID 6 uses two independent parity blocks (XOR + Galois field arithmetic) and survives two simultaneous failures. RAID 6 requires a minimum of four drives and has higher write overhead.
If you are experiencing this issue, learn about our RAID recovery service.