Subnets
Subnetting is something that it somehow always surprises me that people don't immediately understand. This is probably because I have now done three, possibly 4, university courses where I've had to sit through lecturers trying different ways to explain it. In true Top Gear fashion, I thought: "How hard can it be?"
The Problem
As most people are aware, when a computer is connected to a network (specifically, one that uses the Internet Protocol), it is assigned an IP address1. These have to be unique on the network they are on, as they identify the thing connected to the network - not explicitly the computer, but the interface, such as the wireless card or the Ethernet socket. The assigned addresses do not have to be unique across the world, although this is generally restricted to the 'local' block.
IP Addresses are just numbers, which are operated on as binary. If you're not comfortable with binary and bit-wise operations on binary numbers, this will be a bit tricky, and you may just want to smile and nod through the rest of this. There's currently two formats actively in use, IPv4 (which is made of 32 bits (4 bytes)) and IPv6 (which is 16 bytes). I save space, and my ability to do the numbers, I will only give examples of IPv4.
For example the current IP address for one Google server2 is 8.8.4.4 - Google owns all of the addresses between 8.8.0.0 and 8.8.255.255, which is generally notated as 8.8.0.0/16. The problem of subnetting is understanding where that magic /16 comes from.
The Subnet Mask
A mask is the name of any number that is used in some bit-wise operation on another number. If you look at the addresses in the range I gave for some of Google's servers, you can clearly see that they all begin with 8.8. This idea can be viewed:
There exists some x that and some base (network) address n that, for every address a in that address block, a && x = n. Furthermore, networks outside that address block will not have this property
In this case, the first two bytes of the addresses are the same, so the mask in this case is 1111 1111 1111 1111 0000 0000 0000 0000. If this doesn't spring out at you, try writing out the addresses in the range in binary and looking at the values.
So, the first 16 its of the addresses are the same; thus, we say the first 16 bits of the address are the Network Address, and the remainder is the Host address, and that this is a /16 network. The network is then described by the network address address and subnet, bringing us back to the earlier description as 8.8.0.0/16
More Useful Subnets
So far, I have shown you how to stumble across a subnet mask by looking at a block of addresses. They are not, however, just little niceties that happen to appear in the network architecture, but rather create strict sections of the networks, or sub-networks (hence the name).
At home, your router will have two different IP addresses: the external line will have the IP address of main router as seen on the internet, and the internal interface which will have an internal IP address. For convenience, the 192.168.0.0/24 network is used as an internal network when the machines do not have their own global IP addresses.
The router, if it acts as a DHCP (address assignment) server, then knows it can assign the address in the 192.168.0.0/24 block to the machines on one side of it; likewise, it probably has the IP on the other side assigned to it from something higher up the system. In all of these blocks, there are two reserved addresses - the lowest and highest in the block - the all ones address is used for broadcast. This means that the maximum number of hosts on a network is 232-n - 23. This means that a /24 subnet has a maximum of 254 hosts (generally enough for a home network).
A typical problem given in coursework and the like4. You are told that the 'company' you work for has brought a address block, and has a small number of internal networks that need to have IP addresses assigned. In this case we will assume that the company has acquired the address range 210.54.7.0/24. The diagram shows a (rather contrived and stupid) network layout - three routers, each with a line to the internet (going off the diagram). Two of them are acting as gateways to data centers, that have a small number of servers each; the third is the primary router for the companies main office, which has a large number of workstations. The question is, in the most general sense, figure out what subnetworks this layout should be using
The exact numbers I've chosen here are designed to encourage slightly more thought about the problem - there are a number of ways the address range can be divided to form those three networks, which I will mention at the end, and there might be different reasons you pick different implementations; it is a good thing to remember that once of the most expensive thing to do with an electronic system is to have to stop it, change something, and start it again.
What's it use for?
The answer to this is mainly to do with the logical networks (which is covered through some nice thoughts in this thread, and also to do with how information is routed around. If you want to learn more, you can take a look at the way Classless Inter-Domain Routing (CIDR) works.
Solutions to the problem
I'm only going to consider two of two possible solutions to the problem I mentioned earlier - one which does a fair split of the addresses between the networks, and one which gives half of the address space to the office, and splits the other half between the two data centers. Note that the network address and the broadcast address are the values of range of that subnet.
Network | Broadcast Address | Max Hosts | Usage |
---|---|---|---|
210.54.7.0/26 | 210.54.7.63 | 62 | Office |
210.54.7.64/26 | 210.54.7.127 | 62 | Data Center 1 |
210.54.7.128/26 | 210.54.7.191 | 62 | Data Center 2 |
210.54.7.192/26 | 210.54.7.255 | 62 | None |
As you can see, the 'fair' implementation means that the office is only has 2 host addresses space (1, if you assume I haven't counted the router in these figures). This leads to an alternate, more balanced solution
Network | Broadcast Address | Max Hosts | Usage |
---|---|---|---|
210.54.7.0/25 | 210.54.7.127 | 126 | Office |
210.54.7.128/26 | 210.54.7.191 | 62 | Data Center 1 |
210.54.7.192/26 | 210.54.7.255 | 62 | Data Center 2 |
- 1 ↑ except those that assign their own
- 2 ↑ It's one of their DNS servers, which convert host names like 'google.co.uk' into IP addresses
- 3 ↑ There is an exception for the /31 subnet, which has just two hosts and no reserved addresses
- 4 ↑ This is actually adapted from a Department of Computing second year coursework that I vaguely remember