Convert 255.255.255.240 to CIDR notation, and /21 to a dotted mask.
255.255.255.240 has 28 one-bits (24 plus 4 from 240 = 11110000), so it is /28, giving 16 addresses and 14 usable hosts. A /21 is 255.255.248.0.
Explain it simply
A subnet mask is a row of 32 bits: ones for the network part, zeros for the host part, always ones first. CIDR just counts the ones. Converting is counting in either direction.
Example
255.255.255.240
= 11111111.11111111.11111111.11110000
8 + 8 + 8 + 4 = 28 ones -> /28
hosts: 2^4 - 2 = 14
/21 -> 21 ones = 8 + 8 + 5
third octet: 11111000 = 128+64+32+16+8 = 248
mask = 255.255.248.0
hosts: 2^11 - 2 = 2046Common values for one partial octet: 128, 192, 224, 240, 248, 252, 254, 255, which correspond to 1, 2, 3, 4, 5, 6, 7 and 8 ones. A trick is that 256 minus the mask value gives the block size: 256 - 240 = 16.
Masks like 255.0.255.0 are invalid because the ones must be contiguous.
What to say in the interview
"I convert the odd octet to binary and count the ones. 240 is 11110000, so four ones, 24 plus 4 is 28. For /21, 21 is 16 plus 5 ones, giving 248 in the third octet. Block size is 256 minus the mask octet."
Common mistakes
- Writing masks with non-contiguous ones.