James Jason | Software Engineer
Hard drives fail all the time. Lets say you have N hard drives. A simple way to backup all the data is to add another N drives and copy all your data from the old drives to the new ones. Here you will see how using only one extra hard drive can help you recover lost data in case any of the N drives fails. So instead of 2N drives you'll need N+1.Each sample hard drive below has five bits. Even though real drives contain many more, the principles shown here are applicable to any data storage device regardless of its storage capacity.

Step 1) Populate these four hard drives with random bits

Populate each drive with random bits manually ( you can click each box to set its value ) OR by clicking the Populate all drives button. Drives get populated with different pattern of zeros and ones each time the populate all drives button is clicked. Click the Next Step button when you're done.
_
_
_
_
_
Drive 1
_
_
_
_
_
Drive 2
_
_
_
_
_
Drive 3
_
_
_
_
_
Drive 4

Step 2) Learn about the XOR operation

XOR (exclusive or) is a logical operation that takes two binary inputs and outputs 1 only if the inputs differ. It outputs 0 if the inputs are the same. Take a look at the table below and complete the exercise to continue.
XOR Truth Table

Compute the XOR of drive 1 and drive 2.

_
_
_
_
_
Drive 1 XOR Drive 2

Step 3) Compute the parity of the four drives

Taking the XOR of a set of bytes is called "computing their parity". To compute the parity of more than two drives, we can compute the XOR of the first two drives we then take the result and XOR it with the third drive then we again take the result and XOR it with the forth drive and so on. There is an easier way to compute the parity as well. Look at the first bit of each drive below.
  • If their sum is Odd then the first bit of the parity drive is 1.
  • If their sum is Even then the first bit of the parity drive is 0.
To find the second bit of the parity drive, sum the second bit of each drive. Follow the same process to find all the bits of the parity disk. The parity drive will be displayed at the top of this page once this step is completed.
_
_
_
_
_
Parity Drive

Step 4) Select one of the drives to delete

Select any drive you what to delete and click the next step button. The deleted drive will be display at the top of this page (next to the parity drive) for later reference. This step corresponds to drive failure in real RAID systems.

Step 5) Compute the XOR of the parity drive and the remaining three drives

For this step follow the same procedure you used in step three. Look at the first bit of each drive. Do the same for the remaining bits.
  • If their sum is Odd then the first bit of the parity drive is 1.
  • If their sum is Even then the first bit of the parity drive is 0.
_
_
_
_
_
Remaining Drives XOR Parity Drive
Now compare this result with the drive you deleted shown at the top of the page. They are the same! You were able to recover a failed drive by keeping a parity drive. It's noteworthy to mention that the number of hard drives is irrelevant. We used four here, but we could've used a million and we would've gotten the same results.