# 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 first valid IP address
• The last valid IP address

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.

<

h2>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.