## 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!,

## 27 Comments

## RichardS

September 03, 09 2010 05:26:07Good catch!

I really like this explanation

0(from 0 votes)## Lukas

September 06, 09 2010 01:19:59This is realy easy ! like 1 + 1 = 0. Thanks for this.

+1(from 1 vote)## Alaa S.

November 23, 11 2010 08:17:58I give it XOR(111,011)% score, thank you very much for that.

+2(from 4 votes)## Pankaj

April 11, 04 2012 11:51:54It should be XOR(110,010,001) % Score…….

+1(from 3 votes)## Haydn Bell

December 23, 12 2010 10:48:50Understood 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)## Lukas

January 08, 01 2011 10:50:53I 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.

+2(from 4 votes)## Austin Data

October 12, 10 2011 09:44:04this is short! and easy! THANK GOODNESS because raid5 is a terrible bore. thank you!

0(from 2 votes)## Jack

February 21, 02 2012 05:59:26Very 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)## Mike

March 07, 03 2012 08:36:42No, 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)## Mike

March 07, 03 2012 08:38:29Actually, 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)## Chimpidi

March 12, 03 2012 12:52:06Excellent 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)## Nima0102

April 01, 04 2012 07:20:07Excellent and simple explanation.

Thanks a lot.

0(from 0 votes)## Shirish

April 04, 04 2012 01:39:40Gr8 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)## TJ

October 02, 10 2012 09:31:15What 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.

-8(from 22 votes)## kerry

December 27, 12 2013 06:05:12Did 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 expert

November 30, 11 2012 12:15:20Great info. Lucky me I recently found your site by accident (stumbleupon).

I’ve saved as a favorite for later!

0(from 0 votes)## Market

January 01, 01 2013 01:15:35Thank you for simplifying RAID 5, much easier to understand with your XOR example.

0(from 0 votes)## Gabor

February 17, 02 2013 01:12:41Hello,

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

Thanks

0(from 0 votes)## Kasia Kolodziej

February 19, 02 2013 08:30:59Hey 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)## Mansij

March 10, 03 2013 03:15:50.Its really a good & easy explaination…,

about raid…

-1(from 1 vote)## adam

June 28, 06 2013 01:11:12clear 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 Bak

June 28, 06 2013 03:24:50Your 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 Mandol

June 30, 06 2013 02:45:23Very good explanation!!

0(from 0 votes)## Mohammad

October 13, 10 2013 08:55:37So in RAID4 if the parity drive fails, all your data could be lost right?

0(from 0 votes)## Kasia Kolodziej

October 14, 10 2013 08:16:00Losing 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 Rajguru

December 26, 12 2013 07:19:46Really thanks you very much for explanations.

0(from 0 votes)## Subrahmanyam

January 31, 01 2014 09:35:43Good explanation. Thanks

-1(from 1 vote)