Fundamentals of communication and networking: Subnet Masks

PAPER 2 - ⇑ Fundamentals of communication and networking ⇑

← IP address structure Subnet masks IP standards →

Subnet Masks edit

The structure of IPv4 address was devised using classes to indicate the division between the network address and the host address. With increasing pressure on networks to maximise the utilisation of addresses, administrators have subdivided their networks into smaller subnetworks (subnets). Thus the boundary on the 8, 16 or 24-bit point may not be where the division occurs.

In a similar way, several sequential networks can be aggregated to look like a supernetwork (supernet), again the boundary between network and host fields may not be where the class indicates.

Thus we need a different method to indicate where the split is in the IP address. We cannot alter the current structure, so we need an additional parameter.

The Subnet Mask edit

A subnet mask is a 32 bit binary number where a binary 1 indicates a network bit and a binary 0 represents a host bit in the corresponding IP address. Thus subnet masks are always a series of 1s followed by a series of 0s. These masks are used on routers and end devices to indicate where the split is, so the network portion of the corresponding IP address can be identified.

Routers will learn, or be configured with, which subnet masks to use for the networks they are connected to. End devices will learn their subnetmask through DHCP or be configured with the appropriate value.

We can write subnet masks in binary or dotted decimal (just like IP addresses).

Exercise: Subnet masks
What is the subnet mask 11111111 11100000 00000000 00000000 in dotted decimal ?

What does the subnet mask indicate ?


The first 11 bits of the corresponding IP address are network bits and the remaining 21 are host bits.

Thus we can write the default subnet mask for a class A, B and C networks

Class Subnet mask (binary) Subnet mask (decimal)
A 11111111 00000000 00000000 00000000
B 11111111 11111111 00000000 00000000
C 11111111 11111111 11111111 00000000

Using a subnet mask edit

When an IP packet arrives on a router, the router examines the destination address to decide what to do. The router has an internal table (the routing table) which stores all the networks it knows about and the associated interface which leads to that network. The router thus needs to know the destination network of the packet so it can use this as a lookup in the routing table.

When a packet originates on an end device, the end device will need to know if the destination is on the same local network or off on a different network. It does this by examining its own local address to see which network it is on, and then compares this to the destination network of the packet. If the two match, the destination is on its own Local Area Network (LAN). If not it is on a different network and the packet should be forwarded to the default router (sometimes called the gateway).

In the two scenarios above we have an IP address and a subnet mask and have to work out the network address.

The process is to 'bitwise AND' the corresponding bits in the subnet mask and the IP address. The mask acts like a filter, allowing network bits through (where there are 1s in the mask) and blocking host bits (where there are 0s in the mask).

Bitwise AND

Bits Results
0 AND 0 0
0 AND 1 0
1 AND 0 0
1 AND 1 1

Thus given a device with the IP address and the subnet mask, calculate the IP network address of the device

Field Dotted Decimal Binary Dotted Decimal
IP address 11000000 10101000 00000001 00000001
Network Address 11111111 11111111 11111111 00000000
11000000 10101000 00000001 00000000

Thus, an IP packet arriving with a destination address of on an interface is bitwise ANDed with the associated mask of This tells us the destination is on the network and the device can look up where the network is.

Exercise: Calculating Network Addresses
What is the network address of the device with IP address, if the associated mask is a class C? ? ?


Despite the fact the address is a class B address, the mask to be used is class C ( Thus the network address is
A PC with an IP address of pings The mask on this network is Are the two devices on the same network ? ?


Yes. Both are on the same network
Extension: Subnetting, VLSM and CIDR

The networks above have all used subnet masks where the division falls on the 8 bit boundary. This is not always the case. Take an organisation that owns the class C network. It internally divides this into two separate subnetworks by borrowing one bit from the host field. Thus the subnet mask which was for the whole class C network is now for each of the two subnetworks. Work out the network addresses for the two subnetworks. What will be the available range of IP addresses on each subnet?

An ISP has four customers with the following class B IP networks.

  • (each has a default subnet mask of

The ISP wishes to aggregate the four networks into a single network to advertise upstream towards the core. What address and mask could be advertised to represent all four of these networks?