BITAND Function
BITAND Function

BITAND Function

Perform a bitwise AND comparison on two integers. Useful for masks, flag checks, and pulling out specific bits from a value.

ExcelClash Team
PUBLISHED

Summary

BITAND compares two integers at the bit level and keeps only the bits that are 1 in both values. If a bit is missing from either side, it becomes 0 in the result.

This makes BITAND very useful for masks and flag checks. Instead of reading every bit manually, you can test whether a specific bit is on by ANDing the value with a mask and looking at the result.

BITAND is one of the clearest functions for mask-based checks. It lets the worksheet test whether certain flags are present without unpacking the whole number by hand. That is why it is useful in permissions, status fields, and any model where one value stores multiple on/off conditions at once.

Purpose

Keep shared bits

Returns only the bits that are on in both inputs.

Return value

Number

Returns the decimal value of the filtered bit pattern.

Syntax

=BITAND(number1, number2)

number1 and number2 are the integers you want to compare.

Excel compares the two numbers bit by bit and keeps only the positions where both values contain a 1. Even though the logic happens in binary, the returned result is shown as a normal decimal number.

Arguments

  • number1 - [required] The first non-negative integer.
  • number2 - [required] The second non-negative integer.

Both arguments must be whole numbers greater than or equal to 0. In practice, these are usually decimal values that happen to represent bit patterns. If an argument is negative, too large, or not numeric, Excel returns an error instead of trying to guess what you meant.

BITAND vs similar functions

BITAND is for checking overlap between bit patterns, not for adding or toggling them:

Function What it does Typical use Result
BITAND Keeps only shared bits Check whether a flag is set Number
BITOR Combines bits from both values Turn flags on Number
BITXOR Keeps only different bits Toggle or compare changes Number
AND Checks logical conditions TRUE or FALSE tests Boolean

Using BITAND

The most common pattern is using BITAND with a mask. If you want to know whether a specific bit is on, use the bit's value as the second argument. For example, if the mask is 8, then BITAND(value, 8) returns 8 when that bit is on and 0 when it is off.

This is also useful when a single integer stores several flags at once. Instead of breaking the number apart first, you can test one flag at a time with the matching mask. That keeps the formulas short and makes permission-style values much easier to read.

Excel's bitwise functions work with non-negative integers and support values up to 2^48 - 1. If the inputs go outside that limit, Excel returns #NUM!.

Example 1 - Compare 13 and 9

This example compares two decimal values, but the real work happens in binary. BITAND keeps a bit only when that bit is turned on in both numbers.

That is why the result is useful for overlap checks. It tells you which flags, permissions, or bit positions the two values have in common instead of showing every bit from both numbers.

=BITAND(13, 9) // Returns 9
Check Answer
Challenge #1
Target: Sheet1!D1

Find the bitwise AND of 13 and 9.

Example 2 - Check whether bit 8 is set

This example uses 8 as a mask, which means the formula is checking one specific bit position. The question is not "what is the whole number?" but "is this particular bit turned on?"

If the result matches the mask value, that bit is present. If the result is 0, it is not. This is one of the most common ways to test a flag stored inside a larger status number.

=BITAND(12, 8) // Returns 8
Check Answer
Challenge #2
Target: Sheet1!D2

Check if bit 4 (value 8) is set in mask 12.

Example 3 - Test one permission bit

Here the number 7 stores several permissions at once, and the mask 1 targets only the execute bit. BITAND filters the combined value down to just that one part.

This makes permission-style values easier to read because you can test one permission at a time instead of decoding the whole number manually.

=BITAND(7, 1) // Returns 1
Check Answer
Challenge #3
Target: Sheet1!D3

Isolate the "Execute" bit (1) in permission level 7.

Example 4 - Keep only one high bit

This example uses a larger number, but the logic is the same. The formula is checking whether one high-value bit is already present in the input.

The result stays 1024 because that exact bit is on in both places. It is a good reminder that bitwise checks still work the same way even when the bit position is much higher.

=BITAND(1024, 1024) // Returns 1024
Check Answer
Challenge #4
Target: Sheet1!D4

Perform AND on 1024 and 1024.

Conclusion Recap

BITAND is most useful when the question is "which bits do these two values have in common?" In this lesson, that meant checking shared flags, testing whether a specific mask was present, and confirming that only overlapping on-bits survive in the result.

That is why BITAND shows up so often in bitmask work. Instead of scanning a binary pattern by eye, you can compare a value against a mask and let Excel return the matching part as a number. If the result is not zero, the masked bit or group of bits is there.

  • Keeps shared bits: BITAND returns only the bits that are on in both inputs.
  • Great for masks: It is one of the easiest ways to test whether a flag is set.
  • Returns a number: The result is a decimal value, not TRUE or FALSE.
  • Use powers of two as masks: Values like 1, 2, 4, and 8 target individual bits.
  • Works only with non-negative integers: Excel returns #NUM! for values outside the supported range.
Tactical Arena
Share BITAND Function!

Tell your friends about this post

Discussion

ExcelClash is an interactive platform designed to level up your Excel skills through real-world exercises and challenges. Sharpen your logic, solve real spreadsheet problems, and learn faster.

© 2026 ExcelClash, Inc. All rights reserved.