Loading content...
An IP address like 192.168.47.129 appears to be four numbers separated by dots. But which part identifies the network, and which part identifies the specific device? Without additional information, it's impossible to know.
The IP address 192.168.47.129 could represent:
This ambiguity is resolved by the subnet mask—a 32-bit value that explicitly declares where the network portion ends and the host portion begins. The subnet mask is not optional metadata; it is an integral part of how IP addressing functions.
By the end of this page, you will understand: (1) The binary structure and mechanics of subnet masks, (2) Dotted-decimal and CIDR prefix notation, (3) How subnet masks enable the AND operation for routing decisions, (4) Valid vs. invalid subnet mask patterns, and (5) Common subnet masks and their characteristics.
A subnet mask is a 32-bit binary number that masks the network portion of an IP address. When applied to an IP address using a bitwise AND operation, it extracts the network (and subnet) address, stripping away the host identifier.
The Core Concept:
A subnet mask consists of:
The 1s and 0s are always contiguous—all the 1s come first, followed by all the 0s. There is never a 0 followed by a 1 in a valid subnet mask.
Example:
Subnet Mask: 255.255.255.0
Binary: 11111111.11111111.11111111.00000000
└─────── Network Portion ───────┘└─Host─┘
(24 bits) (8 bits)
This mask indicates: "The first 24 bits are the network address; the last 8 bits are the host address."
The contiguous-bits requirement exists because network addresses form hierarchical ranges. If a mask were 11110011, the 'network' addresses wouldn't be contiguous, breaking fundamental routing logic. Every valid subnet mask, when written in binary, is a sequence of 1s followed by a sequence of 0s.
Historical Context:
In the original classful addressing scheme, subnet masks were implicit:
RFC 950 introduced explicit subnet masks that could extend beyond these defaults, enabling the flexible subnetting we discussed in Page 1. Today, subnet masks are always explicit—never assumed from the address class.
To truly understand subnet masks, you must be comfortable with their binary representation. Every subnet mask is a 32-bit value where the pattern is always:
1111...1111 0000...0000
└─ n ones ─┘└─ 32-n zeros ─┘
Converting Between Decimal and Binary:
Each octet (8 bits) converts between decimal and binary independently:
| Binary Octet | Decimal Value | Network Bits in Octet |
|---|---|---|
| 00000000 | 0 | 0 |
| 10000000 | 128 | 1 |
| 11000000 | 192 | 2 |
| 11100000 | 224 | 3 |
| 11110000 | 240 | 4 |
| 11111000 | 248 | 5 |
| 11111100 | 252 | 6 |
| 11111110 | 254 | 7 |
| 11111111 | 255 | 8 |
The Key Pattern:
These are the ONLY valid values for any octet in a subnet mask:
Any other value (like 253, 100, or 177) is invalid because it would have non-contiguous 1s and 0s.
Examples of Invalid Subnet Masks:
255.255.253.0 ← Invalid! 253 = 11111101 (0 between 1s)
255.255.255.100 ← Invalid! 100 = 01100100 (1s not contiguous)
255.0.255.0 ← Invalid! Non-contiguous octets
Transition Octet:
A subnet mask has at most one "transition" octet where the 1s end and 0s begin. All octets before it are 255; all octets after it are 0.
255.255.240.0
│ │ │ └── All zeros (after transition)
│ │ └────── Transition octet (11110000 = 240)
│ └────────── All ones (255, before transition)
└────────────── All ones (255, before transition)
Commit these nine values to memory: 0, 128, 192, 224, 240, 248, 252, 254, 255. If you see any other number in a subnet mask during an exam or troubleshooting, it's an error. These correspond to 0-8 network bits in that octet.
Subnet masks can be expressed in three equivalent formats. Understanding all three is essential because different documentation, tools, and contexts use different formats.
255.255.255.0. This format is used in most operating system network configurations and older documentation. While explicit, it's verbose./24. This compact format has become the standard in modern networking. It appends directly to IP addresses: 192.168.1.0/24.11111111.11111111.11111111.00000000. Rarely used in practice but essential for understanding the mechanics and performing calculations.| CIDR | Dotted-Decimal | Binary | of Hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 11111111.00000000.00000000.00000000 | 16,777,214 |
| /16 | 255.255.0.0 | 11111111.11111111.00000000.00000000 | 65,534 |
| /20 | 255.255.240.0 | 11111111.11111111.11110000.00000000 | 4,094 |
| /24 | 255.255.255.0 | 11111111.11111111.11111111.00000000 | 254 |
| /25 | 255.255.255.128 | 11111111.11111111.11111111.10000000 | 126 |
| /26 | 255.255.255.192 | 11111111.11111111.11111111.11000000 | 62 |
| /27 | 255.255.255.224 | 11111111.11111111.11111111.11100000 | 30 |
| /28 | 255.255.255.240 | 11111111.11111111.11111111.11110000 | 14 |
| /29 | 255.255.255.248 | 11111111.11111111.11111111.11111000 | 6 |
| /30 | 255.255.255.252 | 11111111.11111111.11111111.11111100 | 2 |
| /31 | 255.255.255.254 | 11111111.11111111.11111111.11111110 | 2* |
| /32 | 255.255.255.255 | 11111111.11111111.11111111.11111111 | 1 |
Traditionally, /31 would have 0 usable hosts (2 addresses minus network and broadcast). RFC 3021 permits /31 for point-to-point links where broadcast addresses are unnecessary, allowing both addresses (e.g., .0 and .1) for endpoints. Similarly, /32 identifies a single host (host route).
Converting Between Formats:
CIDR to Dotted-Decimal:
/22 = 11111111.11111111.11111100.00000000
= 255.255.252.0
Dotted-Decimal to CIDR:
255.255.248.0 = 11111111.11111111.11111000.00000000
= 8 + 8 + 5 + 0 = 21 ones
= /21
The subnet mask's practical function is to extract the network address from any IP address using a bitwise AND operation. This operation is fundamental to how every TCP/IP device determines whether a destination is local or remote.
Bitwise AND Rules:
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
When you AND an IP address with a subnet mask:
Worked Example:
Determine the network address for 192.168.47.129 with mask 255.255.255.192 (/26):
IP Address: 192.168.47.129
Binary: 11000000.10101000.00101111.10000001
Subnet Mask: 255.255.255.192
Binary: 11111111.11111111.11111111.11000000
─────────────────────────────────────────────────
AND Result: 11000000.10101000.00101111.10000000
Decimal: 192.168.47.128 Network Address: 192.168.47.128 / 26
Why This Works:
The subnet mask's 1s preserve the network bits exactly. The 0s zero out the host bits, leaving only the network identifier. No matter what host bits were in the original address, ANDing with 0s produces 0s—giving us the base network address.
When a host wants to send a packet, it ANDs its own IP with the subnet mask, then ANDs the destination IP with the same mask. If the results match, the destination is on the same subnet—send directly via ARP. If they differ, the destination is remote—send to the default gateway.
The Local/Remote Algorithm:
Source: 192.168.47.129 / 26
Dest A: 192.168.47.190
Dest B: 192.168.47.65
Mask: 255.255.255.192
Source AND Mask = 192.168.47.128(network address)
Dest A AND Mask:
192.168.47.190 AND 255.255.255.192
= 11000000.10101000.00101111.10111110
AND
11111111.11111111.11111111.11000000
= 11000000.10101000.00101111.10000000
= 192.168.47.128 ← MATCHES source's network!
→ Dest A is LOCAL (same subnet)
Dest B AND Mask:
192.168.47.65 AND 255.255.255.192
= 11000000.10101000.00101111.01000001
AND
11111111.11111111.11111111.11000000
= 11000000.10101000.00101111.01000000
= 192.168.47.64 ← Does NOT match!
→ Dest B is REMOTE (different subnet)
This simple AND comparison, performed billions of times per second across the Internet, is the foundation of IP routing.
For practical work, memorizing key subnet mask values accelerates calculations and troubleshooting. Here's a comprehensive reference organized by the transition octet.
| CIDR | Dotted-Decimal | Block Size | Subnets (from /24) | Hosts/Subnet |
|---|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 1 | 254 |
| /25 | 255.255.255.128 | 128 | 2 | 126 |
| /26 | 255.255.255.192 | 64 | 4 | 62 |
| /27 | 255.255.255.224 | 32 | 8 | 30 |
| /28 | 255.255.255.240 | 16 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 32 | 6 |
| /30 | 255.255.255.252 | 4 | 64 | 2 |
| /31 | 255.255.255.254 | 2 | 128 | 2 (P2P) |
| /32 | 255.255.255.255 | 1 | 256 | 1 (host) |
The Block Size Trick:
The block size (also called increment or jump) is the number of addresses in each subnet. It's calculated as:
Block Size = 256 - (value of transition octet)
For /26 (255.255.255.192):
This mental math shortcut eliminates binary conversion for most practical calculations.
Block sizes are always powers of 2: 256, 128, 64, 32, 16, 8, 4, 2, 1. Subnet boundaries always fall on multiples of the block size. This mathematical elegance comes from binary addressing.
Third-Octet Subnet Masks:
When subnetting crosses into the third octet:
| CIDR | Dotted-Decimal | Block Size (3rd octet) | Hosts |
|---|---|---|---|
| /17 | 255.255.128.0 | 128 | 32,766 |
| /18 | 255.255.192.0 | 64 | 16,382 |
| /19 | 255.255.224.0 | 32 | 8,190 |
| /20 | 255.255.240.0 | 16 | 4,094 |
| /21 | 255.255.248.0 | 8 | 2,046 |
| /22 | 255.255.252.0 | 4 | 1,022 |
| /23 | 255.255.254.0 | 2 | 510 |
The pattern continues identically, just with larger address ranges per subnet.
While subnet masks are used by operating systems and most routing configurations, some network equipment (particularly Cisco routers for access control lists) uses wildcard masks—the bitwise inverse of subnet masks.
The Relationship:
Subnet Mask: 255.255.255.192 (match network bits)
Wildcard Mask: 0.0.0.63 (match host bits)
Subnet Mask + Wildcard Mask = 255.255.255.255 (always)
Why Wildcards Exist:
Wildcard masks originated in Cisco IOS for access control lists (ACLs) where the semantics are inverted:
In an ACL, permit 192.168.1.0 0.0.0.255 means "permit any IP where the first three octets are 192.168.1—the last octet can be anything."
Quick Conversion:
To convert subnet mask to wildcard (or vice versa), subtract each octet from 255:
Subnet: 255.255.255.192
255-255 . 255-255 . 255-255 . 255-192
= 0.0.0.63
Wildcard: 0.0.0.63
Common Wildcard Masks:
| CIDR | Subnet Mask | Wildcard Mask |
|---|---|---|
| /24 | 255.255.255.0 | 0.0.0.255 |
| /25 | 255.255.255.128 | 0.0.0.127 |
| /26 | 255.255.255.192 | 0.0.0.63 |
| /27 | 255.255.255.224 | 0.0.0.31 |
| /28 | 255.255.255.240 | 0.0.0.15 |
| /29 | 255.255.255.248 | 0.0.0.7 |
| /30 | 255.255.255.252 | 0.0.0.3 |
| /32 | 255.255.255.255 | 0.0.0.0 |
Always verify whether a configuration expects a subnet mask or wildcard mask. Using the wrong one is a common misconfiguration error. Cisco ACLs use wildcards; Cisco interface configurations use subnet masks. When in doubt, check the documentation for that specific command.
Subnet masks appear throughout network configurations. Understanding where and how they're specified is essential for practical networking.
12345678910111213
# View current IP configurationipconfig /all # Example output:# IPv4 Address: 192.168.1.100# Subnet Mask: 255.255.255.0# Default Gateway: 192.168.1.1 # Set static IP with subnet masknetsh interface ip set address "Ethernet" static 192.168.1.100 255.255.255.0 192.168.1.1 # PowerShell methodNew-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 192.168.1.100 -PrefixLength 24 -DefaultGateway 192.168.1.1Troubleshooting Subnet Mask Issues:
Incorrect subnet masks cause subtle but serious problems:
Mask too large (e.g., /24 instead of /25)
Mask too small (e.g., /26 instead of /24)
Mask mismatch between devices
When troubleshooting connectivity, always verify the subnet mask on both endpoints. Use ipconfig /all (Windows), ip addr (Linux), or show ip interface (Cisco). A common issue is DHCP assigning correct IPs but incorrect masks due to scope misconfiguration.
The subnet mask is the critical piece of information that gives IP addresses their meaning. Without it, network boundaries are undefined and routing is impossible.
What's Next:
With the subnet mask mechanics understood, we're ready to apply this knowledge to create subnets. The next page covers subnet creation—the process of designing a subnetting scheme that meets organizational requirements for host counts, subnet counts, and efficient address utilization.
You now understand subnet masks at both conceptual and mechanical levels. You can convert between formats, apply the AND operation, and recognize valid mask patterns. This foundation is essential for the subnet creation and calculation exercises ahead.