Sub topic 11
RAID 5: Distributed Parity
This chapter assumes you already know what striping, mirroring, and parity mean at a basic level, and that you can add and subtract drive capacities in TB. If those ideas feel shaky, review the chapter on RAID building blocks first.
By the end, you should be able to describe how RAID 5 lays out data, calculate its usable capacity, explain how it rebuilds a failed drive, and name its common failure modes.
What RAID 5 is
RAID 5 stripes data across three or more drives and stores parity (a calculated value used to rebuild lost data) alongside it. The parity is not kept on one dedicated drive. Each stripe puts its parity block on a different drive, rotating from stripe to stripe. This is why RAID 5 is called striping with distributed parity.
Key facts for the exam:
| Property | RAID 5 |
|---|---|
| Minimum drives | 3 |
| Fault tolerance | 1 drive failure |
| Usable capacity | (N − 1) × drive size |
| Read performance | Good, because reads are spread across all drives |
| Write performance | Slower, because parity must be calculated and written |
| Typical use | File servers and general business storage where capacity and some redundancy both matter |
How the layout works
Consider four drives. Each row below is one stripe. Each stripe holds three data blocks and one parity block. The parity block moves to a different drive in each row.
Rotating the parity matters for performance. If parity lived on one dedicated drive (as in RAID 4), that drive would be written on every write and would become a bottleneck. Spreading parity evenly shares that work among all drives.
How parity works
RAID 5 parity is the XOR (exclusive OR) of the data blocks in a stripe. XOR returns 1 when its two inputs differ and 0 when they match. A useful property of XOR is that applying it again undoes it. If you XOR all the surviving blocks in a stripe, including the parity block, you get the missing block back.
# Three data blocks striped across three drives (4-bit values for readability)
a = 0b1010
b = 0b0110
c = 0b1100
# The parity block is the XOR of all data blocks
parity = a ^ b ^ c
print(format(parity, "04b")) # 0000
# If the drive holding b fails, XOR the survivors to rebuild it
rebuilt_b = a ^ c ^ parity
print(format(rebuilt_b, "04b")) # 0110
print(rebuilt_b == b) # TrueThe same math works for any block that goes missing, whether it was data or parity. That is why one failed drive of any position can be survived.
Calculating usable capacity
One drive's worth of space in the array goes to parity. The formula is (N − 1) × drive size, where N is the number of drives. All drives are treated as the size of the smallest one.
def usable_capacity(level, drives, size_tb):
"""Return usable capacity in TB for a RAID level."""
if level == 0 and drives >= 2:
return drives * size_tb
if level == 1 and drives == 2:
return size_tb
if level == 5 and drives >= 3:
return (drives - 1) * size_tb
if level == 6 and drives >= 4:
return (drives - 2) * size_tb
if level == 10 and drives >= 4 and drives % 2 == 0:
return (drives // 2) * size_tb
raise ValueError("Drive count not valid for this RAID level")
print(usable_capacity(0, 4, 2)) # 8
print(usable_capacity(1, 2, 2)) # 2
print(usable_capacity(5, 4, 2)) # 6
print(usable_capacity(6, 4, 2)) # 4
print(usable_capacity(10, 4, 2)) # 4For RAID 5 with four 2 TB drives, usable capacity is (4 − 1) × 2 = 6 TB. Adding drives improves efficiency. Three drives give 67% usable space, four give 75%, and eight give about 88%. Only one drive's worth is ever lost to parity.
What happens when a drive fails
When one drive fails, the array enters a degraded state. It keeps working, and users can still read and write. Each read that would have touched the failed drive is instead computed by XOR-ing the other drives. Performance drops during this time.
The process works like this:
- A drive fails and the controller marks the array degraded.
- You replace the drive, or a hot spare (an idle drive held ready) takes over automatically.
- The controller rebuilds the missing data onto the new drive by reading every surviving drive and calculating the missing blocks.
- When the rebuild finishes, the array returns to normal.
During step 3, the array has no redundancy. A second drive failure before the rebuild completes means total data loss for the array.
Common errors and gotchas
- Mixed drive sizes. The array uses the smallest drive's size for every member. Four drives of 2, 2, 2, and 4 TB give (4 − 1) × 2 = 6 TB, and the extra 2 TB is wasted.
- Large drives and long rebuilds. Rebuild time grows with drive size, from hours to days on very large drives. A long rebuild widens the window in which a second failure can occur. This is the main reason RAID 6, which survives two failures, is preferred for large arrays.
- Unrecoverable read errors. During a rebuild, a bad sector on a surviving drive can make a block unreadable. With no redundancy left, the controller cannot reconstruct it. This can fail the rebuild.
- Write penalty. A small write requires reading the old data and old parity, computing new parity, and writing both. One logical write becomes several disk operations. RAID 5 is a poor fit for write-heavy workloads such as busy databases.
- Treating it as a backup. RAID 5 protects against one drive failing. It does not protect against deletion, corruption, malware, controller failure, fire, or theft.
RAID 5 compared with its neighbors
| Level | Minimum drives | Failures survived | Usable capacity (N drives) | Main trade-off |
|---|---|---|---|---|
| RAID 0 | 2 | 0 | N × size | Fast, no redundancy |
| RAID 1 | 2 | 1 | 1 × size | Simple, 50% efficiency |
| RAID 5 | 3 | 1 | (N − 1) × size | Good capacity, slower writes |
| RAID 6 | 4 | 2 | (N − 2) × size | Safer, more parity overhead |
| RAID 10 | 4 | 1 per mirror pair | (N / 2) × size | Fast and resilient, 50% efficiency |
Exam scenario thinking
A typical question describes a small office that needs good read speed, protection from one drive failure, and efficient use of its drives. Three or more drives with one drive's worth of parity points to RAID 5. If the scenario stresses high write performance and fast rebuilds, RAID 10 is usually a better answer. If the scenario says the array must survive two simultaneous drive failures, choose RAID 6.
Exercise
A server has five 4 TB drives in a RAID 5 array. How much usable capacity does it have, and what happens if two drives fail at the same time?
Show answer
Usable capacity is (5 − 1) × 4 TB = 16 TB. RAID 5 tolerates only one drive failure, so if two drives fail at once the array is lost and the data must be restored from backup.
Exercise
An array has three drives: 1 TB, 2 TB, and 2 TB, configured as RAID 5. What is the usable capacity, and why?
Show answer
Usable capacity is (3 − 1) × 1 TB = 2 TB. RAID 5 treats every member as the size of the smallest drive, so the extra capacity on the two 2 TB drives goes unused.
Exercise
Why does RAID 5 spread the parity blocks across all drives instead of keeping them on one drive?
Show answer
A dedicated parity drive would be written on every write operation and would become a bottleneck. Distributing parity spreads the extra write work evenly across all drives.