IPv4 and Subnet Mask
This is where the pieces lock together. A device finds its network by performing a bitwise AND between its address and its mask. In this lesson you do that arithmetic by hand, extract the network and broadcast addresses, and then prove it on a full set of practice problems and exam-style questions.
The AND operation
AND is a boolean (logic) operation on two bits. Its rule is simple: the result is 1 only when both input bits are 1; otherwise the result is 0.
255 or 0 (for example /26 and /27); and solve practice and exam-style multiple-choice questions with confidence.| Bit A | Bit B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
AND is applied column by column across all 32 bits. This matters because a mask
bit of 1 passes through the corresponding address bit unchanged
(x AND 1 = x), while a mask bit of 0 clears it (x AND 0 = 0). So the network
bits survive and the host bits are zeroed out — which is precisely how the network address
is born.
255, the result
octet equals the address octet (it passes through). When a mask octet is 0, the result
octet is 0. You only need full binary AND for a mask octet that is neither
255 nor 0 (for example 192, 224, or 240).Network address = IP AND mask
Place values: 128 64 32 16 8 4 2 1
192 : 1 1 0 0 0 0 0 0 (11000000)
AND
255 : 1 1 1 1 1 1 1 1 (11111111)
=
192 : 1 1 0 0 0 0 0 0 (11000000) -> network bit passes through
45 : 0 0 1 0 1 0 1 0 (00101010)
AND
0 : 0 0 0 0 0 0 0 0 (00000000)
=
0 : 0 0 0 0 0 0 0 0 (00000000) -> host bit cleared
Read the two examples together: every address bit under a mask 1 is kept, and every
bit under a mask 0 becomes 0. That is the whole mechanism.
Worked examples
Three examples, from easy to the tricky one. Work each through before reading the answer underneath it.
Worked example 1 — /24
Question: what is the network address of 192.168.10.45 with mask
255.255.255.0?
IP : 11000000.10101000.00001010.00101010 (192.168.10.45) Mask : 11111111.11111111.11111111.00000000 (255.255.255.0) AND : 11000000.10101000.00001010.00000000 (192.168.10.0)
| Octet | IP | Mask | Result | Why |
|---|---|---|---|---|
| 1 | 192 | 255 | 192 | mask = 255, pass through |
| 2 | 168 | 255 | 168 | mask = 255, pass through |
| 3 | 10 | 255 | 10 | mask = 255, pass through |
| 4 | 45 | 0 | 0 | mask = 0, cleared |
Network = 192.168.10.0. The host part is 45; the broadcast is
192.168.10.255, and the usable range is 192.168.10.1–.254.
Worked example 2 — /16
Question: find the network, broadcast and host count for
172.16.20.200/16 (mask 255.255.0.0).
IP : 10101100.00010000.00010100.11001000 (172.16.20.200) Mask : 11111111.11111111.00000000.00000000 (255.255.0.0) AND : 10101100.00010000.00000000.00000000 (172.16.0.0)
- Network: 172.16.0.0 (the last two octets are host bits, so they clear).
- Broadcast: set all host bits to 1 → 172.16.255.255.
- Usable range: 172.16.0.1 – 172.16.255.254.
- Host bits: h = 32 − 16 = 16, so usable hosts = 216 − 2 = 65,534.
Worked example 3 — /26
Question: what subnet does 192.168.1.100/26 belong to? Here the mask
octet is neither 255 nor 0, so we AND in binary.
Mask 255.255.255.192, which is 11111111.11111111.11111111.11000000.
Only the last octet needs real bit math:
Place values: 128 64 32 16 8 4 2 1 100 : 0 1 1 0 0 1 0 0 (01100100) AND 192 : 1 1 0 0 0 0 0 0 (11000000) = 64 : 0 1 0 0 0 0 0 0 (01000000)
So network = 192.168.1.64. The block size is
256 − 192 = 64, so the /26 subnets step by 64: .0, .64,
.128, .192. Our host (100) sits in the .64 block, which runs
from .64 to .127.
- Network: 192.168.1.64 (not usable)
- Broadcast: 192.168.1.127 (all host bits 1; not usable)
- Usable range: 192.168.1.65 – 192.168.1.126
- Usable hosts: h = 6, so 26 − 2 = 62
Finding the broadcast address
Once you have the network address and the block size, the broadcast is the last address before the next subnet begins. Two reliable methods:
- Set all host bits to 1. Take the network address and flip every host bit to 1.
- Add block size − 1 to the network address (in the interesting octet).
.64 block are: .64 / .65 / .126 / .127. Learn this
four-number pattern — it is what the exam asks for.Practice problems (with solutions)
Work each one on paper before opening the answer.
P1. Convert 203.0.113.7 to binary.
11001011.00000000.01110001.00000111.P2. What class and default mask is 128.10.20.30?
P3. Is 172.31.255.254 a private address?
P4. Give the network and broadcast for 10.50.20.130/24.
P5. How many usable hosts are in a /27 subnet?
P6. AND 192.168.15.200 with 255.255.255.224. Give the network, broadcast, first and last usable host.
P7. Convert 255.255.255.240 to prefix notation and state the usable hosts.
P8. Is the host 192.0.2.5 routable across the public Internet?
P9. Find the network and broadcast for 172.16.100.25/17 (mask 255.255.128.0).
Exam-style multiple choice
Choose one answer, then open the item to check.
Q1. How many bits are in an IPv4 address? A) 8 B) 16 C) 32 D) 64
Q2. Which address is private? A) 172.15.1.1 B) 172.16.1.1 C) 172.32.1.1 D) 192.169.1.1
Q3. What is 255.255.255.224 in prefix notation?
A) /24 B) /25 C) /27 D) /30
Q4. How many usable host addresses does a /24 provide? A) 24 B) 254 C) 255 D) 256
Q5. What is the network address of 192.168.10.45 with mask 255.255.255.0?
A) 192.168.10.0 B) 192.168.10.1 C) 192.168.10.45 D) 192.168.10.255
Q6. Which block is reserved for loopback? A) 10.0.0.0/8 B) 127.0.0.0/8 C) 169.254.0.0/16 D) 100.64.0.0/10
Q7. What is the broadcast address of 192.168.5.0/24?
A) 192.168.5.0 B) 192.168.5.1 C) 192.168.5.254 D) 192.168.5.255
Q8. A host 192.168.1.100/26 belongs to which subnet?
A) 192.168.1.0 B) 192.168.1.64 C) 192.168.1.96 D) 192.168.1.128
Q9. A PC displays the address 169.254.20.5. What is the most likely cause?
A) duplicate address B) DHCP server unreachable C) DNS failure D) wrong subnet mask
Q10. Using 2h − 2 with h = 6 gives: A) 30 B) 62 C) 64 D) 126
Key terms
AND
Logical operation returning 1 only when both input bits are 1.
Network address
IP AND mask; all host bits 0; identifies the subnet and is not usable by a host.
Broadcast address
Network address with all host bits set to 1; reaches every host in the subnet.
Block size
256 − (interesting mask octet); the step between consecutive subnets.
Interesting octet
The octet where the mask is neither 255 nor 0, so full binary AND is needed.
Usable range
The addresses between the network address and the broadcast address, inclusive.
Sources & references
- Postel, J. RFC 791: Internet Protocol (1981). Address masking and subnet structure.
- Braden, R. RFC 1122: Requirements for Internet Hosts — Communication Layers (1989).
- Rekhter, Y. et al. RFC 1918: Address Allocation for Private Internets (1996).
- Arkko, J., Cotton, M. & Vegoda, L. RFC 5737: IPv4 Address Blocks Reserved for Documentation (2010).
- Cotton, M. & Vegoda, L. RFC 5735: Special Use IPv4 Addresses (2010).
- Cheshire, S., Aboba, B. & Guttman, E. RFC 3927: Dynamic Configuration of IPv4 Link-Local Addresses (2005).
- Weil, J. et al. RFC 6598: IANA-Reserved IPv4 Prefix for Shared Address Space (2012).
- IANA. IPv4 Special-Purpose Address Registry.
- Cisco. CCNA (200-301) Exam Topics, Network Fundamentals (IP addressing and subnetting).
Review
Check what you have learned with these review questions.
Sources & references
- Postel, J. RFC 791: Internet Protocol (1981). Address masking and subnet structure. rfc-editor.org/rfc/rfc791.
- Braden, R. RFC 1122: Requirements for Internet Hosts — Communication Layers (1989). rfc-editor.org/rfc/rfc1122.
- Rekhter, Y. et al. RFC 1918: Address Allocation for Private Internets (1996). rfc-editor.org/rfc/rfc1918.
- Arkko, J., Cotton, M. & Vegoda, L. RFC 5737: IPv4 Address Blocks Reserved for Documentation (2010). rfc-editor.org/rfc/rfc5737.
- Cotton, M. & Vegoda, L. RFC 5735: Special Use IPv4 Addresses (2010). rfc-editor.org/rfc/rfc5735.
- Cheshire, S., Aboba, B. & Guttman, E. RFC 3927: Dynamic Configuration of IPv4 Link-Local Addresses (2005). rfc-editor.org/rfc/rfc3927.
- Weil, J. et al. RFC 6598: IANA-Reserved IPv4 Prefix for Shared Address Space (2012). rfc-editor.org/rfc/rfc6598.
- IANA. IPv4 Special-Purpose Address Registry. iana.org.
- Cisco. CCNA (200-301) Exam Topics, Network Fundamentals (IP addressing and subnetting). cisco.com.
Target exams: CCNA 200-301 v1.1 · CyberOps Associate 200-201. Last content verification: 2026-10-11.