ZetCode

Excel XOR Function

last modified October 5, 2026

The XOR function is a logical function in Excel that performs an exclusive OR operation. It returns TRUE when an odd number of conditions are TRUE, and FALSE otherwise. This tutorial provides a comprehensive guide to using the XOR function with detailed examples. You'll learn basic syntax, practical applications, and how it differs from other logical functions.

XOR Function Basics

The XOR function performs an exclusive OR operation on multiple logical conditions. Unlike OR which returns TRUE if any condition is TRUE, XOR returns TRUE only when an odd number of conditions are TRUE.

Component Description
Function Name XOR
Category Logical
Syntax =XOR(logical1, [logical2], ...)
Arguments 1 to 254 logical values or references
Return Value TRUE or FALSE

This table breaks down the essential components of the XOR function. It shows the function name, category, basic syntax format, argument limits, and return value characteristics.

Argument Required Meaning
logical1 Yes The first condition to test. It can be the constants TRUE or FALSE, a comparison such as A1>10, a number, or a cell reference or range that contains logical values.
logical2, ... No Additional conditions, up to a total of 254 arguments. Each one is evaluated as TRUE or FALSE before the exclusive OR is applied.

XOR requires at least one argument. Numbers are accepted and are coerced so that 0 is FALSE and every other number is TRUE. Text is not a logical value: inside a referenced range text and empty cells are ignored, but if the range then contains no logical values at all, the result is the #VALUE! error.

XOR Truth Table

With two logical values, XOR returns TRUE when exactly one of them is TRUE. It returns FALSE when both are TRUE or when both are FALSE. The following table shows all four combinations.

A B A XOR B
TRUE TRUE FALSE
TRUE FALSE TRUE
FALSE TRUE TRUE
FALSE FALSE FALSE

With three or more logical values, the two-input intuition no longer holds. XOR returns TRUE when an odd number of the arguments are TRUE and FALSE when an even number are TRUE. This is the parity rule, and it is the most important thing to remember about the function.

A B C TRUE count A XOR B XOR C
FALSE FALSE FALSE 0 (even) FALSE
TRUE FALSE FALSE 1 (odd) TRUE
FALSE TRUE FALSE 1 (odd) TRUE
FALSE FALSE TRUE 1 (odd) TRUE
TRUE TRUE FALSE 2 (even) FALSE
TRUE FALSE TRUE 2 (even) FALSE
FALSE TRUE TRUE 2 (even) FALSE
TRUE TRUE TRUE 3 (odd) TRUE

Because the rule depends only on the count of TRUE values, XOR is associative: =XOR(A1,B1,C1) gives the same result as =XOR(XOR(A1,B1),C1). This property is what makes the function useful for parity and checksum calculations.

Basic XOR Example

This example demonstrates the simplest use of the XOR function with two logical conditions.

Basic XOR formula
=XOR(TRUE, FALSE)

This formula compares TRUE and FALSE. The result will be TRUE because exactly one condition is TRUE. XOR returns TRUE when an odd number of conditions are TRUE.

XOR with Multiple Conditions

XOR can evaluate multiple conditions. This example shows how it behaves with three logical values.

A B C
TRUE TRUE FALSE
=XOR(A1, B1, C1)

The table shows three logical values and an XOR formula evaluating them. With two TRUEs and one FALSE, the result will be FALSE because the number of TRUE conditions is even.

XOR with multiple conditions
=XOR(A1, B1, C1)

This formula evaluates A1 (TRUE), B1 (TRUE), and C1 (FALSE). The result is FALSE because there's an even number (2) of TRUE conditions. XOR returns TRUE only for odd counts of TRUE conditions.

XOR with Cell References

A practical use of XOR involves referencing cells containing logical values. Here's an example with cell references.

A B C
TRUE FALSE
FALSE TRUE
=XOR(A1:B2)

This table demonstrates XOR evaluating a range of cells (A1:B2) containing logical values. The formula will check how many TRUE values exist in the range.

XOR with cell range
=XOR(A1:B2)

This formula evaluates all cells in A1:B2. With two TRUE values (A1 and B2), the result is FALSE because the count of TRUEs is even. XOR treats ranges by counting all TRUE values in the range.

XOR with Numeric Values

XOR treats numbers as logical values where 0 is FALSE and every non-zero number, including a negative number, is TRUE. This example demonstrates that behavior.

A B C
1 0
5 0
=XOR(A1:B2)

The table shows numeric values being evaluated by XOR. The formula converts these to logical values before performing the exclusive OR operation.

XOR with numeric values
=XOR(A1:B2)

This formula evaluates A1 (1=TRUE), B1 (0=FALSE), A2 (5=TRUE), B2 (0=FALSE). There are two TRUE values, so XOR returns FALSE. This automatic conversion makes XOR flexible for different data types.

XOR with Text and Empty Cells

Text is not a logical value. When a direct argument is text, XOR returns the #VALUE! error. When text or an empty cell sits inside a referenced range, that entry is ignored, but the range must still contain at least one logical value or XOR returns #VALUE!.

A B Result
TRUE "Yes" =XOR(A1:B1) returns TRUE (text ignored)
"Yes" "No" =XOR(A2:B2) returns #VALUE! (no logical values)
TRUE (blank) =XOR(A3:B3) returns TRUE (blank ignored)

The first row contains one logical value, so the text is discarded and XOR returns TRUE. The second row contains only text, so there is nothing left to evaluate and Excel reports #VALUE!. The third row shows that a blank cell is ignored in the same way.

XOR with text and blank cells
=XOR(A1:B1)      ' TRUE, text is ignored
=XOR(A2:B2)      ' #VALUE!, no logical values found
=XOR(A3:B3)      ' TRUE, blank is ignored
=XOR("Yes","No") ' #VALUE!, direct text is not logical

To turn text into a logical value, compare it first. For example, =XOR(A1="Yes", B1="No") is valid because each comparison produces TRUE or FALSE, and XOR then combines those results.

XOR vs OR vs BITXOR

XOR is often confused with the inclusive OR and with the bit-level BITXOR. They answer different questions, as the table below shows.

Function Operates on Example Result
OR Logical values =OR(TRUE, TRUE) TRUE
XOR Logical values =XOR(TRUE, TRUE) FALSE
XOR Logical values =XOR(TRUE, FALSE) TRUE
BITXOR Integer bits =BITXOR(5, 3) 6

OR returns TRUE if at least one condition is TRUE, so two TRUEs give TRUE. XOR returns FALSE when two TRUEs cancel out. BITXOR is a different function entirely: it works digit by digit on the binary representation of integers. Because 5 is 101 and 3 is 011 in binary, the bitwise exclusive OR is 110, which is 6. Use XOR for logical conditions and BITXOR for bit manipulation.

XOR is also the opposite of equality for two logical values: =XOR(A1, B1) is equivalent to =NOT(A1=B1) and to =A1<>B1. In plain language, XOR answers "one or the other, but not both".

XOR for Exclusive Conditions

The most common use of XOR is requiring exactly one of two conditions to be met. This example checks a promotion rule where an employee must pass a test or have a recommendation, but not both.

A B C
TRUE FALSE
=XOR(A1, B1)

Because only the first condition is TRUE, the formula returns TRUE. If both conditions were TRUE, or if neither were TRUE, the result would be FALSE. This "either this or that, but not both" logic is exactly what XOR adds beyond OR.

Exclusive condition
=IF(XOR(A1="Pass", B1="Recommended"), "Promote", "Review")

Nesting XOR inside IF turns the exclusive condition into a readable decision formula.

XOR for Parity Checking

Because XOR returns TRUE for an odd count of TRUE values, it is the natural tool for parity checks. A parity bit is a single value that records whether the number of set bits in a message is odd or even.

A B C D
TRUE TRUE FALSE =XOR(A1:C1)

The range contains two TRUE values, an even count, so the parity formula returns FALSE. Adding a connected range of up to 254 flags makes it easy to detect an odd or even number of exceptions in a row of data.

Parity of a range
=XOR(A1:Z1)

This formula is TRUE when an odd number of cells in A1:Z1 are TRUE. It is a concise alternative to summing the flags and testing =MOD(SUM(--A1:Z1), 2)=1.

XOR for Toggling

XOR with a fixed FALSE or TRUE acts as a conditional toggle. Exclusive-ORing a value with FALSE leaves it unchanged, while exclusive-ORing it with TRUE flips it. This is useful for remembering state that alternates.

Toggling a Boolean
=XOR(A1, FALSE)   ' keeps the value of A1
=XOR(A1, TRUE)    ' flips the value of A1

If A1 holds TRUE, the first formula returns TRUE and the second returns FALSE. The same idea appears in the checkerboard example below, where XOR of the row and column parity flips the pattern at every step.

XOR in Conditional Formatting

XOR can be used in conditional formatting rules to create alternating patterns. This example shows how to apply it.

XOR in conditional formatting
=XOR(MOD(ROW(),2)=1, MOD(COLUMN(),2)=1)

This formula creates a checkerboard pattern by XORing row and column parity. A cell is formatted when exactly one of its row or column is odd, so the pattern alternates at every intersection. Use it as a formula-based rule, with the references adjusted for the top-left cell of the selected "Applies to" range; Excel updates the relative references for the other cells automatically.

XOR Errors and Troubleshooting

Cause Symptom Fix
No arguments at all "Too few arguments" message XOR requires at least one argument; supply a logical value
No argument is a logical value #VALUE! error Make sure the referenced range contains TRUE/FALSE or numbers
Text passed directly as an argument #VALUE! error Use a comparison such as A1="Yes" instead of raw text
A range contains only text or blank cells #VALUE! error Text and blanks are ignored; add a logical value to the range
Referenced cell holds an error The same error is passed through Test with ISERROR or wrap the formula in IFERROR
Function name misspelled or old Excel version #NAME? error XOR requires Excel 2013 or later
Two TRUE values expected to return TRUE FALSE result XOR returns TRUE for an odd count only; use OR for "any"

The XOR function is the exclusive OR of Excel's logical family. With two conditions it means "one or the other, but not both", and with more conditions it reduces to a parity test that returns TRUE for an odd number of TRUEs. Remember the two rules that cause most mistakes: numbers are coerced so that 0 is FALSE and every other value is TRUE, and text is not a logical value, so it is ignored inside ranges and returns #VALUE! when passed directly. Mastering XOR gives you a compact way to express exclusive conditions, parity checks, and toggling logic in Excel.

Author

My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.

List all Excel Formulas.