IPv4 subnets

Type an IP with its mask and watch how the network is worked out: the bitwise AND is done byte by byte, with the network and host bits split by the mask’s cut. The network address, the broadcast address, the host range and how many hosts fit are calculated for you, and you can check whether another IP is on the same network. It runs in your browser, on your phone too.

How to use it

  1. Type the IP with its prefix (10.110.7.24/24) or with the mask (10.110.7.24 255.255.255.0). Start with the room 7 one, the same as in the theory article.
  2. Change the prefix with − and + and watch the cut between network and host move.
  3. Press Step to watch the AND byte by byte, or Run to watch it all. Each step explains the maths and, if the mask splits a byte, does it bit by bit.
  4. Below are the results and same network?: type another IP and it tells you whether delivery is direct or goes through the router. Share copies a link with your IP.

How to read the AND

Each row is the 32 bits of an address, in four bytes, with the decimal value underneath. In violet, the network bits (where the mask has a 1); in coral, the host bits (where it has a 0). The network comes from an AND: where the mask has a 1, the IP bit gets through; where it has a 0, it becomes 0. The broadcast address is the network with every host bit set to 1.

The maths

  • With h host bits (h = 32 − n) there are 2h addresses. Two are never given to a host, the network and the broadcast ones, so 2h − 2 hosts fit: from network + 1 to broadcast − 1.
  • With /31 there are 2 addresses and both are used on a point-to-point link; with /32, just one: the host itself.
  • The class (A, B, C, D or E) is read from the first bits, as in the course notes. Networks are written with /n (CIDR) today, but the class still comes up in the exam.
  • Two IPs are on the same network if the AND with the same mask gives the same network. If not, the packet goes to the default gateway (the router).

Common mistakes

Forgetting to subtract the two addresses when counting hosts (/24 is 254 hosts, not 256), giving a host the network or broadcast address, and writing a mask that is not contiguous: in binary a mask is always a run of ones followed by a run of zeros, so 255.0.255.0 is not valid. If you type one like that, the simulator tells you why.