IPv4 - subnet mask
A subnet mask is a 32-bit number used to distinguish the network and host parts of an IPv4 address. It works in conjunction with an IP address to identify which portion of the address is dedicated to the network and which portion is dedicated to the host.
In an IP address and its associated subnet mask, the network bits are represented with '1's and the host bits are represented with '0's. The format is binary, but it's commonly written in dotted decimal format. For example, the subnet mask most commonly used in small networks is typically 255.255.255.0. In binary, that would be represented like so:
Thus, this subnet mask shows that the first three octets are network bits and the final octet is for host bits.
The subnet mask can also be represented in slash prefix format, which is simply a forward slash "/" followed by the number of ones in the subnet mask. The above subnet mask would be represented like so: /24 since it has 24 ones.
The subnet mask is crucial when a packet of information is being sent over a network. The sending machine uses the subnet mask to determine whether the destination IP address is on the same local subnet or whether the packet needs to be sent to the default gateway to reach a different network. If the destination IP address shares the same network bits as the source IP address (as determined by the subnet mask), then it's on the same network; otherwise, the packet needs to be forwarded to the router.
For example, let's say Host A with address 10.10.10.56/24 wants to send a packet to Host B with an address of 10.10.10.12/24. Let's take a look at these addresses in their binary formats. Note that the first 24 bits of both addresses which are the network portions as defined by their subnet masks, have been made bold:
10.10.10.56 = 00001010.00001010.00001010.00111000 10.10.10.12 = 00001010.00001010.00001010.00001100
Are these network portions (bolded bits) the same for both addresses? Yes, therefore, the destination IP address is on the same subnet, and the packet can be sent directly to the destination.
Let's take a look at another example. Let's say Host A with address 10.10.10.56/24 wants to send a packet to Host C with an address of 10.10.11.22/24. Let's take a look at these addresses in their binary formats. Again, the first 24 bits of both addresses which are the network portions as defined by their subnet masks, have been made bold:
10.10.10.56 = 00001010.00001010.00001010.00111000 10.10.11.22 = 00001010.00001010.0000101<font style="color:green" "bold">1.00010110
Note here that the network portions (bolded) are not the same, therefore the destination address is on a different subnet, therefore, the packet must be sent to the default gateway to be routed to that different subnet.
Links to this page:
- ACL wildcard mask
- BGP Advertising a prefix
- BGP Advertising a route using the Null0 exit interface
- DHCP relay agent
- IP Routing table - process by which entries are matched
- IPv4 - classful addressing
- IPv4 - classless addressing
- IPv4 - no subnet mask information in the IP header
- IPv4 Subnetting invalid entry causing network address of zero
- IPv4 network and broadcast addresses
- IPv6 - prefix length
- IPv6 minimum and maximum prefix lengths
- NAT prefix-length keyword on nat pool command
- Network - Example of communication, encapsulation, and decapsulation, between hosts
- OSPF advertising loopback network
- OSPF network command
- OSPF requirements for forming adjacency
- Routing what if the administrative distance is the same
- Serial Interface default broadcast address
- Switching - switched virtual interface (SVI)
- VPN - default gateway of VPN client
- Wireless - configure a 1941W router with a single subnet on wired and wireless interfaces