# Parity- What is it?

In this post, we’re going to look into what parity is. Depending on your background, you may or may not be familiar with the term and/or what it actually is. Or perhaps you’ve heard of the parity bit, which yes, is related.

The good news is that parity is a straight-forward concept. Some of its applications, for example in different RAID groups, can get more complicated, but today we’ll be sticking with the basics.

In computer science, maintaining integrity of data is extremely important for ensuring intended functionality and preventing data corruption or manipulation. Different methods of error checking exist to make sure integrity has not been compromised; parity is one method of error checking.

#### What is parity?

Parity checking is a way to validate data. Parity itself can be considered as something being even or odd.

#### What is a parity bit?

A parity bit can be used to essentially “save” the state of a set of bits such that after data has been transferred, a change in the data could be noticed.

This occurs through first noting the number of 1’s in a sequence of bits. The parity bit is used to track the expected number of bits whose value should be 1. You can use either an even parity bit or an odd parity bit. An even parity bit is used to maintain or creates an even number of 1’s; an odd parity bit would be used to maintain or create an odd number of 1’s.

Here’s an example:

Take the 7-bit sequence 0100110. This is what it looks like to add an eighth parity bit:

Even parity bitOdd parity bit
0100110101001100

#### How does parity checking work?

The error checking occurs after the data has been transferred. The parity bit is checked, and if the number of 1’s is not even (when using an even parity bit) or odd (when using an odd parity bit), then it can be recognized that the data integrity was not maintained.

Let’s do another example:

We’ll keep the same 7-bit sequence from above, 0100110, and use an even parity bit.

Expected dataCorrupted data
0100110100001101

How do we know something went wrong? Because the eighth bit, our parity bit, is a 1, we know there should be an odd number of 1’s in the rest of the sequence (or an even number total, if you include the parity bit). Unfortunately, there are only two 1’s in the first seven bits, meaning something changed.

#### Limitations of Parity Checking

Following from the example above, let’s look at what information may not be conveyed through parity checking.

1. We won’t necessarily know if a bit that was initially 0 turned to a 1, or if a bit that was initially 1 switched to a 0.
2. For both cases in #1, we don’t know if those cases occurred multiple (an odd number of) times and/or if both types of changes happened.
3. Most importantly, this method will not catch cases where an even number of bit value swaps occurred, either creating more or less 0’s or more or less 1’s. When that happens, the parity is still technically the same. For example, above we know that three 1’s means something went wrong. However, if an additional 1 had swapped to 0, or vice versa, the parity would have still ended up even, showing no sign of error.

*Note: For #1 and #2, you may not actually care. In many cases, you will just need to know that the data isn’t what it was expected to be.

And there you have it! That’s what parity, parity checking, and parity bits are and are used for.