Hone

Lessons · IT support · IP address and subnet mask

An IP address is a street and a house; the mask says where the street ends

An IPv4 address is 32 bits written as four numbers, 0 to 255 each. The subnet mask says how many of those bits, from the left, name the network (the street) and how many are left to name the host (the house). A mask of 255.255.255.0 is 24 ones then 8 zeros, written /24.

Hone is a place to practise a career, one idea a day. This is one of its lessons, written out in full and free to read without an account.

What it is for

Two machines on the same switch cannot see each other's shared folder. Their addresses are 10.4.2.31 and 10.4.3.31 and the mask on both is 255.255.255.0. They look a digit apart and they are on different streets; the mask is what says so. Without it you can stare at the two addresses all afternoon.

How to think about it

Write the address, then the mask, then the mask as a prefix: count the ones. 255 is eight ones, 0 is eight zeros; the in-between numbers (128, 192, 224, 240, 248, 252) are one to six ones. Network bits are the prefix; host bits are 32 minus it. The network address is the address with every host bit set to 0; the broadcast is the same with every host bit set to 1. Neither one is ever a machine.

Worked example

10.4.2.31, mask 255.255.255.0 → /24
Three octets of ones is 24 ones. Network bits 24, host bits 8.
Network 10.4.2.0, broadcast 10.4.2.255
Host bits all 0, then all 1. The machines live in between.
255.255.255.192 → 11111111.11111111.11111111.11000000 → /26
192 is 11000000: two more ones. Twenty-six network bits, six host bits.
255.255.254.0 → /23
254 is 11111110: seven ones in the third octet. Sixteen plus seven is twenty-three.

Your turn

Write the prefix length for the mask 255.255.255.224.

255.255.255.224 → /

The trap

Reading the mask as a number that is 'almost 255' and therefore 'almost the same'. 255.255.255.0 and 255.255.0.0 are one octet apart in the writing and 256 times apart in the size of the street.

Practise IP address and subnet mask on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.