Bitwise Masks: AND, OR and Prefix Lengths
What a mask does
A mask is a bit pattern used to select or change positions in another pattern. Bitwise operations work on corresponding bits, not whole numbers as true/false values. AND preserves a bit when the mask has 1 and clears it when the mask has 0. OR sets a bit when the mask has 1 and leaves it unchanged when the mask has 0.
A B | AND OR0 0 | 0 00 1 | 0 11 0 | 0 11 1 | 1 1Work through AND and OR
Write decimal 173 as 10101101 and decimal 240 as 11110000. Compare one column at a time: AND gives 10100000, or 160. OR gives 11111101, or 253. The two operations answer different questions: AND selects the upper four bits; OR sets the upper four bits. Neither operation is ordinary addition.
A 10101101 (173)Mask 11110000 (240)AND 10100000 (160)OR 11111101 (253)Prefix masks and powers of two
A prefix identifies the leading bits of an address. In IPv4, a CIDR prefix length counts leading network bits out of 32; a /26 mask has 26 ones followed by six zeros. The final octet is 11000000 (192), so the dotted mask is 255.255.255.192. The remaining six bits permit 2^6 = 64 patterns; this counts addresses, not necessarily assignable hosts. Full subnetting and special cases come later.
Use a mask to identify an address block
Consider the documentation address 192.0.2.173 with /26. AND the corresponding octets with 255.255.255.192. The first three octets stay unchanged. In the last octet, 10101101 AND 11000000 = 10000000 (128). The block starts at 192.0.2.128 and ends at 192.0.2.191 because it contains 64 addresses. This is paper arithmetic, not an instruction to assign or advertise the address.
Recognize incorrect masks
A modern IPv4 prefix mask must have contiguous ones from the left, followed only by zeros. A pattern such as 10100000 is useful as a general bit mask but is not a valid partial octet of a CIDR mask. Do not confuse a prefix mask with a vendor wildcard mask (a different matching convention covered later). Practice: AND 206 with 224 and state the five remaining variable bits in a /27 IPv4 block.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Bitwise masks — knowledge check
Apply offline network mathematics to fictional values.
What is 206 AND 224, using eight-bit numbers?
What is 5 OR 10?
Which is a valid partial octet in a CIDR prefix mask?
How many address patterns does a /27 IPv4 block contain?
What is the final octet of the block start for 192.0.2.206/27?