IP addressing questions come up in almost every networking interview and in many embedded and hardware interviews too, because so many devices now sit on a network. This post answers the common ones: what an IP address is, how the network and host parts are split, what subnet masks and prefixes mean, which ranges are private, and how IPv6 addresses are written. The deep dive works through subnetting examples with numbers.
What is an IP address?
An IP address identifies a network interface so that packets can be delivered to it. An IPv4 address is 32 bits long and is written as four decimal numbers from 0 to 255 separated by dots, for example 192.168.1.10. Each number is one byte (an octet).
What are the network part and the host part?
Every IPv4 address is split into two parts. The leading bits identify the network, and the remaining bits identify the host on that network. Routers forward packets by looking at the network part; the host part only matters once the packet reaches the right network.
What is a subnet mask, and what does /24 mean?
The subnet mask says where the split falls. A mask of 255.255.255.0 has 24 one-bits followed by 8 zero-bits, so the first 24 bits are the network part. The same thing is written in prefix notation as /24, which simply counts the one-bits. 192.168.1.10/24 means "host 10 on network 192.168.1.0".
What were address classes?
Early IPv4 used fixed classes: the first bits of an address decided whether it was Class A, B or C, and so how big the network was. RFC 4632, the current description of Classless Inter-Domain Routing (CIDR), summarizes them: Class A gave 128 networks of about 16 million hosts each, Class B about 16,000 networks of 65,536 addresses, and Class C about 2 million networks of 254 hosts. Classes wasted addresses, so CIDR replaced them with prefixes of any length. Interviewers still ask about classes, but real networks use prefixes.
Which addresses are private?
RFC 1918 (February 1996) reserves three blocks for private networks, which are not routed on the public Internet:
- 10.0.0.0 to 10.255.255.255 (10/8)
- 172.16.0.0 to 172.31.255.255 (172.16/12)
- 192.168.0.0 to 192.168.255.255 (192.168/16)
Home routers and office networks use these, and a NAT (network address translation) device maps them to a public address when traffic goes out to the Internet. A further block, 100.64.0.0/10, is set aside by RFC 6598 as shared address space for service providers running carrier-grade NAT.
What are the network and broadcast addresses?
In a normal subnet, the address with all host bits 0 names the network itself, and the address with all host bits 1 is the broadcast address. Neither is given to a host, which is why a /24 has 256 addresses but only 254 usable host addresses.
How is IPv6 different?
IPv6 addresses are 128 bits long. RFC 4291 defines how they are written: eight groups of up to four hexadecimal digits separated by colons, with one run of zero groups allowed to be shortened to "::". The loopback address is ::1, and link-local addresses start with FE80::/10. The same prefix idea applies: 2001:db8:0:1::/64 is a network whose first 64 bits are fixed, leaving 64 bits for interface addresses.
Deep dive: the numbers and details
This part holds the subnetting formulas and worked examples. Skip it if the overview is all you need.
The two formulas you need
For an IPv4 prefix of length n:
- Addresses in the subnet: 2^(32 - n)
- Usable host addresses: 2^(32 - n) - 2 (network and broadcast addresses removed)
| Prefix | Mask | Addresses | Usable hosts |
|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
One exception: RFC 3021 allows /31 prefixes on point-to-point links, where both addresses are used as host addresses because a link with two ends needs no broadcast. Its stated benefit is that each such link uses two addresses instead of four.
Worked example 1: which subnet is a host in?
Question: host 192.168.10.77/26. What are the network address, the broadcast address and the usable range?
- A /26 has 64 addresses, so subnets in the last octet start at 0, 64, 128 and 192.
- 77 falls between 64 and 127, so the network address is 192.168.10.64.
- The broadcast address is the last in the block: 192.168.10.127.
- Usable hosts: 192.168.10.65 to 192.168.10.126, which is 62 addresses.
In binary, the last octet 77 is 01001101. The /26 mask keeps the first two bits of that octet (01), giving 01000000 = 64 for the network, and setting the other six bits to 1 gives 01111111 = 127 for the broadcast.
Worked example 2: splitting a block
Question: you have 10.20.0.0/24 and need four subnets of at least 50 hosts each. What prefix and which subnets?
- 50 hosts need at least 52 addresses (50 + 2). The smallest power of two that fits is 64, which is 2^6, so the prefix is 32 - 6 = /26.
- A /24 holds 256 / 64 = 4 subnets of /26, exactly enough.
- The subnets are 10.20.0.0/26, 10.20.0.64/26, 10.20.0.128/26 and 10.20.0.192/26.
Worked example 3: is this address private?
Question: is 172.20.5.1 private? The private block is 172.16.0.0/12. A /12 fixes the first 12 bits: the first octet 172 and the top four bits of the second octet. 16 in binary is 0001 0000, so the second octet can run from 0001 0000 (16) to 0001 1111 (31). 20 is in that range, so yes. 172.32.0.1 is not private.
Worked example 4: route aggregation
RFC 4632 gives an example of why prefixes help routing: a provider holding 10.24.0.0/13 can hand out smaller blocks such as 10.24.0.0/21 and 10.24.16.0/20 to customers, but advertise only the single route 10.24.0.0/13 to the rest of the Internet. Fewer routes mean smaller routing tables.
Quick-fire interview questions
- How many usable hosts in a /27? 30.
- What mask is /20? 255.255.240.0.
- What is 127.0.0.1? The IPv4 loopback address; IPv6 uses ::1.
- Can two devices on different private networks use the same address? Yes; private addresses only have to be unique within their own network, and NAT handles the connection to the outside.
- Shorten 2001:0db8:0000:0000:0000:0000:0000:0001. 2001:db8::1.
Common mistakes
- Forgetting to subtract the network and broadcast addresses when counting hosts.
- Starting subnets on boundaries that are not multiples of the block size.
- Treating all of 172.x.x.x as private, rather than only 172.16 to 172.31.
- Using "::" twice in one IPv6 address, which makes it ambiguous.


Your comments will be moderated before it appears here.