# What is parity in computing?

In computers, parity (from the Latin *paritas*, meaning "equal or equivalent") is a technique that checks whether data has been lost or written over when it is moved from one place in storage to another or when it is transmitted between computers.

Parity generally refers to the state of equality or equivalence between two or more things: people, prices, purchasing power and mathematical functions. In computing, parity is the quality of a byte of data -- stored in a computer's RAM -- of being even or odd. For this reason, it is also known as *RAM parity*.

This concept is usually used in the context of a parity bit, which is a redundant check bit and used for to validate data and find errors during data transmission. The job of the parity bit is to help the data recipient detect any errors that might have occurred during the transmission of that data. Parity check is also known as *vertical redundancy check,* or VRC.

## How parity works

Because data transmission is not an entirely error-free process, data is not always received in the same way as it was transmitted. A parity bit adds checksums into data that help the target device determine whether the data was received correctly.

An additional binary digit, the parity bit*,* is added to a group of bits that are moved together. This bit, sometimes referred to as a *check bit*, is used only to identify whether the moved bits arrived successfully.

## What is a parity bit?

A parity bit is a single bit of data appended to a binary string. Its value can be either 0 or 1. Depending on its value, the sum of all the data bits will be even or odd.

If the parity bit is odd and the stream of bits contains an even number of 1s, the total number will be odd, so the computer will produce an error. An error will also be produced if the parity bit is even and the stream of bits contains an odd number of 1s, producing an even number.

For every eight bits of actual data, adding a parity bit extends the length of the data string to nine bits. This additional bit is stored in an additional individual memory chip.

## The importance of parity and parity bits

A parity check using a parity bit is particularly useful when there is a need to check for errors during the transmission or reading of data from a storage device. Such errors are common because data bits can and do change from a 1 to a 0 or vice versa. This is known as *bit flipping*.

The parity bit can detect such errors by identifying mismatches in the transmission and by checking if the number of received data bits matches the expected parity. If there is no match, an error is generated. For example, if a binary sequence has even parity but the total number of ones is *not* even, it could indicate an error.

## Even parity bit vs. odd parity bit

There are two kinds of parity bits.

In even parity, the number of bits with a value of 1 are counted. If that number is odd, the parity bit value is set to 1 to make the total number of ones in the set, including the parity bit, an even number. If the number of bits with a value of 1 is even, the parity bit value is set to 0 so the total number of ones in the set, including the parity bit, remains an even number.

In odd parity, if the number of bits with a value of 1 is an even number, the parity bit value is set to 1 to make the total number of ones in the set, including the parity bit, an odd number. If the number of bits with a value of 1 is odd, the parity bit value is set to 0 so the total number of ones in the set, including the parity bit, remains an odd number.

In either case, each group of incoming bits is checked at the receiving end to see if the group totals to an even or odd number. If a transmission error occurs, the transmission is retried, or the system halts and an error message is sent to the user.

When it comes to choosing the parity bit, there is no right or wrong value. The choice depends on the system or application and the specific requirements.

## Applications of parity error detection

The previous description explains how parity checking works within a computer. Specifically, the peripheral component interconnect bus and the I/O bus controller use the odd parity method of error checking.

Parity bit checking is not an infallible error-checking method since it's possible that two bits could be in error in a transmission, offsetting each other. For transmissions within a personal computer, this possibility is considered extremely remote. In some large computer systems where data integrity is extremely important, three bits are allocated for parity checking.

Parity checking is also used in communication between modems. Here, parity checking can be selected to be even -- a successful transmission forms an even number -- or odd. Users may also select no parity, meaning the modems will not transmit or check a parity bit. When no parity is selected or defaulted to, it's assumed there are other forms of checking that will detect any errors in transmission. No parity also usually means the parity bit can be used for data, speeding up transmission. In modem-to-modem communication, the type of parity is coordinated by the sending and receiving modems before the transmission takes place.

## Parity and RAID

The concept of parity is also used in redundant array of independent disk protection. RAID devices use enhanced forms of parity checking, such as vertical and horizontal parity. Some RAID groups, such as RAID 4 or RAID 5, have one or more disk drives that contain parity information that lets them rebuild data if a drive failure occurs.

For example, double-parity RAID, also known as RAID 6, stripes data across a set of at least four drives at a block level, like RAID 5, but then writes a second set of parity data across all the drives. This approach guards against data loss in up to two failed drives. Drawbacks to double-parity RAID include the use of a complex controller, the cost of two extra drives for implementation and slower write transactions due to the extra parity set.

When data is written to a RAID group, it will always have the correct parity, as it will have gone through various error-checking algorithms. That way, if a drive in the RAID group fails, the system uses the information on the remaining disks along with the parity information to rebuild the data on the failed drive to a spare drive.

How does this happen? If the RAID group is using even parity, it can figure out what was on the failed drive by adding up the bits on the remaining drives. If the data on the remaining drives adds up to an odd number, the information on the failed drive must have been a one to maintain even parity. If the data on the remaining drives adds up to an even number, the data on the failed drive must have been a zero.

## Parity checking vs. error-correction code and cyclic redundancy checks

Parity checking is not the only method used for error detection in computing.

At the 64-bit word level, parity checking and error-correction code (ECC) require the same number of extra bits. While parity checking just detects an error -- it does not have correction capabilities -- ECC technology allows errors to be detected and corrected. This means a system can continue to work without data being corrupted. In general, ECC offers greater reliability to any computing or telecommunications system without adding much cost.

Another alternative to parity bits is cyclic redundancy checks, or checksums, a method that can help with the detection of multiple errors, particularly in storage media. In this method, a value or checksum is generated based on the data being transmitted. The checksum has a fixed value, is appended to the data, and is then sent along with the data. On receiving the data with the checksum, the receiver recalculates the checksum value and checks if it matches the appended value. If the calculated and received checksum match, the data was transmitted correctly. A mismatch indicates an error in data transmission.

When both error detection and correction are required, techniques, such as forward error correction (FEC), are used instead of parity bits. An FEC code adds redundancy to the transmitted data so the data recipient can reconstruct the original message even if there are errors. There's no need to retransmit the entire data to correct the errors.

*RAID protects data and improves storage performance and availability, but it can be confusing. Compare the types and benefits of RAID.*