3

2010

# How does RAID 5 work? The Shortest and Easiest explanation ever!

**We all have limited time to study long and complicated information about RAID theories, but you may be interested as to how RAID 5 works. We made it simple for you by providing the shortest and easiest explanation ever. **

### RAID 5 – how it works?

First we need to remind you XOR definition:

XOR function result is equal 1 if both arguments are different.

XOR (0, 1) = 1

XOR (1, 0) = 1

XOR function output is equal 0 if both arguments are same.

XOR (0, 0) = 0

XOR (1, 1) = 0

Now let us assume we have 3 drives with the following bits:

| 101 | 010 | 011 |

And we calculate XOR of those data and place it on 4^{th} drive

XOR (101, 010, 011) = 100 (XOR (101,010) = 111 and then XOR (111, 011) = 100

So the data on the four drives looks like this below:

| 101 | 010 | 011 | **100** |

Now let’s see how the XOR MAGIC works. Let’s assume the second drive has failed. When we calculate XOR all the remaining data will be present from the missing drive.

| 101 | ** 010 ** | 011 | 100 |

XOR (101, 011, 100) = 010

You can check the missing other drives and XOR of the remaining data will always give you exactly the data of your missing drive.

| 101 | 010 | ** 011** | 100 |

XOR (101, 010, 100) = 011

What works for 3 bits and 4 drives only, works for any number of bits and any number of drives. Real RAID 5 has the most common stripe size of 64k (65536 * 8 = 524288 bits )

So the real XOR engine only needs to deal with 524288 bits and not 3 bits as in our exercise. This is why the RAID 5 needs a very efficient XOR engine in order to calculate it fast.

So when adding one drive for parity you will be able to rebuild the missing data in case of any drive failure.

In our example we have explained RAID 4 where parity is on a dedicated drive. RAID 5 will distribute parities evenly between all drives. Distributed parity provides a slight increase in performance but the XOR magic is the same.

To learn more about RAID 5 please go to Wikipedia article.

### RAID – The Series. Check out:

How does RAID 5 work? The Shortest and Easiest explanation ever!,

## Related Posts

## 27 Comments + Add Comment

## Leave a comment

## DATA STORAGE SOFTWARE

- Support for NAS, iSCSI, FibreChannel
- High-Availability over 2 nodes
- Reasonable pricing

RichardSSeptember 3, 2010 at 5:26 pmGood catch!

I really like this explanation

0(from 0 votes)LukasSeptember 6, 2010 at 1:19 pmThis is realy easy ! like 1 + 1 = 0. Thanks for this.

+1(from 1 vote)Alaa S.November 23, 2010 at 8:17 amI give it XOR(111,011)% score, thank you very much for that.

+1(from 3 votes)PankajApril 11, 2012 at 11:51 amIt should be XOR(110,010,001) % Score…….

0(from 2 votes)Haydn BellDecember 23, 2010 at 10:48 amUnderstood 3 drive, but wasn’t sure how 4 drive worked. Excellent explaination, simply phrased so even I could catch it on first read. Have just built my first 4 drive Raid 5 PC. Many thanks !!!

0(from 0 votes)LukasJanuary 8, 2011 at 10:50 pmI will try to help you …

In case of using more than 3 drivers you must use the same calculation for xor:

XOR 0,0=0

XOR 0,1=1

XOR 1,0=1

XOR 1,1=0

Example

4 drives with following data:

1,1,0,1

1,0.0.0

0,0,1,0

0,1,1,0

We calculate XOR of those data and place it on 5th drive;

for the 1st line XOR(1,1,0,1)=1

for the 2nd line XOR(1,0,0,0)=1

for the 3th line XOR(0,0,1,0)=1

for the 5th line XOR(0,1,1,0)=0

so the data looks like these:

1,1,0,1,1

1,0,0,0,1

0,0,1,0,1

0,1,1,0,0

and now let simulate break of 3rd drive

1,1,x,1,1

1,0,x,0,1

0,0,x,0,1

0,1,x,0,0

so we must get the data for this drive so we must calculate XOR for x from 1st 2nd 4th and 5th drive:

x for the 1st line from XOR(1,1,1,1)=0 why ? 1,1=0 -> 0,1=1 -> 1,1=0

x for the 2nd line from XOR(1,0,0,1)=0

x for the 3rd line from XOR(0,0,0,1)=1

x for the 4th line from XOR(0,1,0,0)=1

You have to always calculate sum of two numbers and the result calculate with the next number. Action is alternately for XOR.

I hope this helps.

+1(from 3 votes)Austin DataOctober 12, 2011 at 9:44 pmthis is short! and easy! THANK GOODNESS because raid5 is a terrible bore. thank you!

0(from 2 votes)JackFebruary 21, 2012 at 5:59 pmVery good explain. Thanks

If my 2 disks are failed at a time, out of 7 disks, is it possible to get the data in raid 5. I know raid can tolerate only one disk failure, sometime it makes me confuse.

Thanks in advanced.

0(from 0 votes)MikeMarch 7, 2012 at 8:36 pmNo, the data is unrecoverable. simply put, raid 5 only tolerates a single drive failure because of the way xor works, if you had data of 1010, and lost 2 drives making it x01x, there’s no way to calculate both of the missing values. Raid 6 would work because of a double parity.

0(from 0 votes)MikeMarch 7, 2012 at 8:38 pmActually, I should have used 7 drives in my example, but the math is the same, 0101010, 2 drives missing, 01x101x, still don’t know if the total string should add up to a 1 or a 0.

0(from 0 votes)ChimpidiMarch 12, 2012 at 12:52 pmExcellent explanation. I tried in different sites and got the concept but I was not clear about how the parity plays a role. The explantion given here, clears off my questions. Thanks alot for the details.

0(from 0 votes)Nima0102April 1, 2012 at 7:20 amExcellent and simple explanation.

Thanks a lot.

0(from 0 votes)ShirishApril 4, 2012 at 1:39 pmGr8 Explanation !!

But Need to explain how your read/write operation works on RAID5.. that is actual point .. in case of parity ..

–Shirish Shukla

0(from 0 votes)TJOctober 2, 2012 at 9:31 pmWhat do you guys mean great explanation??? This is a half-way explanation. How about starting out by EXPLANING what the heck XOR is??? What does it stand for? What is it? Where did it come from? Is it just a variable?? That’s like those people who tell stories about people you’ve never heard of before as if you should know who they are: “So me and Bill went to John’s house and then Phil walked in”. Come on…..

And if that’s not enough, how about explaning what XOR (101,010) = 111 actually means. I’m guessing by way of simple addition that they are adding the bits together on the left side and then subtracting them on the other, but still……….NO EXPLANATION!!! You know how I can tell a developer write this little “explanation”? Because this is exactly the type of stuff developers do and they have no idea why people have to keep asking them 50 questions. It’s not because we’re stupid, it’s because they give half explanations.

But other than that it’s pretty cool.

-6(from 20 votes)kerryDecember 27, 2013 at 6:05 amDid you read the article or are you just dumb? The author very clearly explained XOR. I am not a developer and I have never heard of XOR before. I understood RAID generally but could not understand how you got redundancy with only 4 drives and capacity equal to 3 drives w/ RAID 5. This explanation cleared it up for me. You still have questions b/c you can’t read or (more likely), you have low intellect.

+2(from 4 votes)nyc seo expertNovember 30, 2012 at 12:15 pmGreat info. Lucky me I recently found your site by accident (stumbleupon).

I’ve saved as a favorite for later!

0(from 0 votes)MarketJanuary 1, 2013 at 1:15 amThank you for simplifying RAID 5, much easier to understand with your XOR example.

0(from 0 votes)GaborFebruary 17, 2013 at 1:12 pmHello,

Could you please explain to me how the raid6 works when two drives missing?

Thanks

0(from 0 votes)Kasia KolodziejFebruary 19, 2013 at 8:30 amHey Gabor!

For RAID6, the minimum required disks are four. Two drives can be missing and the system will still work. However, you have to remember that in case these two drives will be rebuilding, the performance might be slower.

You can find more info here and here.

0(from 0 votes)MansijMarch 10, 2013 at 3:15 am.Its really a good & easy explaination…,

about raid…

-1(from 1 vote)adamJune 28, 2013 at 1:11 pmclear and simple. so does this mean that there is always a disk dedicated to the “checksum” in a raid5 configuration? Or is both data and XOR bits are distribuited on all drives?

0(from 0 votes)Janusz BakJune 28, 2013 at 3:24 pmYour question is answered in last 2 sentences of my article. In fact I was describing RAID4, but my goal was to make clear how XOR magic works for parity in RAID. My goal was also to make the explanation really easy and short. This is why I have started with RAID4 and referenced to RAID5 Wikipedia post which is already long and much more complicated to understand. The difference between RAID4 and RAID5 is only that RAID5 distributes parity and RAID4 keeps parity in a dedicated drive. It is not so important if you want just understand how parity calculation works.

0(from 0 votes)Samit MandolJune 30, 2013 at 2:45 amVery good explanation!!

0(from 0 votes)MohammadOctober 13, 2013 at 8:55 pmSo in RAID4 if the parity drive fails, all your data could be lost right?

0(from 0 votes)Kasia KolodziejOctober 14, 2013 at 8:16 amLosing the parity disk in RAID 4 is NOT a problem for the data.

You will just have the data without parity.

So, your RAID array is in the degraded mode – as next disk fail will cost data loss.

After replacing the drive, the rebuild task will re-create the parity based on the data.

Once the parity is re-created, your RAID array status switches from degraded to normal.

And now, the array is ready to tolerate the next disk fail and does not lose all the data.

+2(from 2 votes)Jignesh RajguruDecember 26, 2013 at 7:19 amReally thanks you very much for explanations.

0(from 0 votes)SubrahmanyamJanuary 31, 2014 at 9:35 amGood explanation. Thanks

-1(from 1 vote)