# IPv4 subnetting for mere mortals

I've been taking some networking classes and one of the prerequisites is to be able to calculate IP address ranges for subnetting a network. Here is an example problem that needs to be solved: Say that you have a private class B address. You're using the 5th branch of that network. Now you need to subnet that network for subnets containing at most 8 interfaces (Computers, Tablets, Printers, etc..). You'll need to determine the IP range of the 10th subnet.

Here are the things that you'll need to figure out.

• The network IP address
• The first valid IP address
• The last valid IP address
• The broadcast address
• And the subnet mask

So how do you do this? What will you do? Read on, true believer!

## Bits are what makes the network go round and round

You probably know by now that computers run on a binany numbering scheme. 1 and 0 are the only things that a computer knows or cares about. (We're not talking about quantum computing here). So 1 = 1, 10 = 2, 11 = 3, 100 = 4, 101 = 5, and so on. You just count in groups of two instead of the familiar groups of 10 in the decimal system that we all know and (sometimes) love. IP addresses consist of 32 bits, separated in 4 groups of 8 bits. For example IP address 1.1.1.1 is really 00000001.00000001.00000001.00000001, and IP address of 255.255.255.255 would be written out in binary like so: 11111111.11111111.11111111.11111111 Keep this in mind as you work through the exercise.

## Classes? I don't need no stinking classes!

(Well actually, you do) Private network classes are classed by letter, with classes A, B, and C being commonly used. Classes D is an oddball class that deals with multicast IP addresses that are far beyond the scope of this tutorial. Class E The IP address ranges of the classes are as follows (Where x is any number between 0 and 255) Class A: 10.x.x.x (16,777,216 IP addresses available) with a default subnet of 255.0.0.0 or /8 Class B: 172.16-31.x.x (1,048,576 IP addresses available) with a default subnet of 255.240.0.0 or /12 Class C: 192.168.x.x (65,536 IP addresses available) with a default subnet of 255.255.0.0 or /16 That's a lot of IP addresses, and to use those IP addresses efficiently you'll want to subnet your network if it is large enough. (We're talking larger than what is typically in a SOHO network)

In the example above, we want the 5th branch of a private class B network. This branch would be located at 172.20.0.0 (172.16 is the first branch of a class B network, and count up from there). The pattern I think it's easiest to visualize the various parts of a network's IP address in 3 different parts. We have a network section (n), a subnet section (s), and a host section (h). Let identify the parts on a per-bit in the binary IP address. We know we want 172.20.???.??? as our network address, which on a per bit basis would be nnnnnnnn.nnnnnnnn.?.? Why? The first two numbers are our network bits, and they will never change. Each number is 8 bits so the first 16 bits will be part of the network section of the ip address pattern.

What we need to figure out now is the number of subnet bits (identified by "s" in the pattern) and host bits (identified in the pattern by an "h")

## Slice and dice with class

To subnet a network, there are two rules that must be obeyed if you want to use the classful way: You can never have less than 2 subnets on your network (You're borrowing host bits to make subnets) You can never have less than 2 hosts on a subnet Essentially for this example you can never have a pattern of: nnnnnnnn.nnnnnnnn.shhhhhhh.hhhhhhhh (you need at least 2 "s" bits in the pattern) nnnnnnnn.nnnnnnnn.ssssssss.sssssssh (you need at least 2 "h" bits in the pattern) Back to our exercise. What we need to figure out is the number of bits that will accomodate 8 interfaces. What is 8 in binary? it's 1000. And that is your answer, you're going to need 4 bits for your hosts ("h" bits), and the rest of the bits will be subnet bits ("s" bits).

The pattern is starting to take shape at this time like so: nnnnnnnn.nnnnnnnn.ssssssss.sssshhhh (16 network bits, 12 subnet bits, and 4 host bits) Bear in mind that host bits are always at the end of the patten, network bits at the start of the pattern, and subnets are kinda squished in between.

## Binary numbers are fun!

Now that we have our pattern, we need to start thinking in binary to answer the rest of the questions of this exercise. What would be the 10th subnet of our network? To do that we need to start replacing pattern bits with binary numbers. So 10 in binary is 10000 which will replace the "s" bits in the pattern like so: nnnnnnnn.nnnnnnnn.ssssssss.sssshhhh nnnnnnnn.nnnnnnnn.00000001.0000hhhh Notice what we did there? We snuck in 10000 in place of the last 5 "s" bits and then replace the remaining "s" bits wil leading zeroes. Since we aren't caring about the host bits just yet we can just zero them out as well. which will completely replace out pattern like so: nnnnnnnn.nnnnnnnn.ssssssss.sssshhhh nnnnnnnn.nnnnnnnn.00000001.00000000 What this does, is that it answers our subnet IP address.

What is a subnet IP address exactly? Well It is the IP adress that with the help of a subnet mask, identifies the range of IP addresses for that subnet. Well be calculating the subnet in a bit, but this finally begins to answer the questions of the exercise: The network IP address: 172.20.1.0 The first valid IP address that you can assign to a host is the next IP address up so: The first valid IP address: 172.20.1.1 The last valid IP address is the IP address just below the broadcast addresss, which is itself the very last IP address of the subnet range. How do we figure the broadcast IP? Easy if switch all your host bits to 1 in the pattern, like so: nnnnnnnn.nnnnnnnn.ssssssss.sssshhhh nnnnnnnn.nnnnnnnn.00000001.00001111 And 1111 binary switched to the decimal system is 15, The broadcast address: 172.20.1.15 The last valid IP address: 172.20.1.14 (remember the last usable IP is the one just before the broadcast address) And the subnet mask: ?

## The head. It hurts!

We're almost there, and we're at the easy part! We just need to answer the last question of what is the subnet mask of the subnet. That's pretty easy, you just need to count the number of network "n" and subnet "s" bits in the pattern, like so: nnnnnnnn.nnnnnnnn.ssssssss.sssshhhh That's 28 bits for the subnet mask and you write it out like so: /28 (so the network address would acually be 172.20.1.0 /28

EXTRA CREDIT BONUS ROUND! You can't write /28 in a subnet mask input line in your computer's configuration. You'll probably need to switch it to a x.x.x.x notation. Again, it is pretty easy, you just need to switch all network "n" and subnet "s" bits in the pattern to 1, the host "h" bits to 0, and start calculating. It would look like this: nnnnnnnn.nnnnnnnn.ssssssss.sssshhhh 11111111.11111111.11111111.11110000 or 255.255.255.240 The answer So the whole answer for the exercise is as follows: The network IP address: 172.20.1.0 The first valid IP address: 172.20.1.1 The last valid IP address: 172.20.1.14 The broadcast address: 172.20.1.15 And the subnet mask: 255.255.255.240 or /28 I know that the whole process may seem daunting the first time around. But it really does get easier with practice! Just pick a class, branch and number of required hosts or subnets and start calculating!