Skip to content
Pvtw

Subnetting

What is subnetting? and why you need to? That's what I'm going to answer here. But first the very basic:

What is an IP address?

An ip address is basically the phone number of your device. It is used to communicate to the internet and to other devices in your network. The device you're using to read this post, has a ip address. On a computer you can find out the ip addres with this command:

ipconfig

or on linux:

ifconfig

You'll get something like this: ipconfig

IPv4 is your local ip address and only valid in your network. Your router gave it to your device with something called DHCP. Everything you connect to your router, through a cable or wifi, will get a private ip address. In home networks a router is mostly also a modem, switch and WAP (Wireless Access Point). The subnet mask is mysterious. For now, when you see 255, that means the corresponding octet of your ipv4 address does not change. A zero means that number can change.
Then you see the default gateway. That is the ip address of your router. The router makes it possible to visit the internet. When you visit my website, the router will check what ip address my website has and if it's not in your network, your router knows it must go outside your network; to the internet.

The ip addresses are organized in classes:

Class Ranges Default subnet mask
A 1.0.0.0 - 126.255.255.255 255.0.0.0
B 128.0.0.0 - 191.255.0.0 255.255.0.0
C 192.0.0.0 - 223.255.255.0 255.255.255.0
D 224.0.0.0 - 239.255.255.255 -
E 240.0.0.0 - 255.255.255.255 -

An eagle eye can see there is a range missing. That is right, the range 127.0.0.0 - 127.255.255.255. This address is called the loopback address and refers to the current device. Class D is what we call the multicast address.
Class E is experimental and cannot touch it.

Help! We ran out!

We don't have enough public ip addrress for every device. That's why we have private ip addresses. You ISP gave you one single public ip address and your router has a way to translate your local private ip address to the public ip address when you acces the internet. That means every device in your network shares the same public ip address.

Binary

Binary is the language of one's and zero's. Before we can subnet, you have to know how to convert a ip address to binary. It is very easy if we use a little chart like this:

Decimal 128 64 32 16 8 4 2 1
Bits

Let's take this ip address: 192.168.1.44 and convert it to binary. We take the first octet go from left to right on the chart and first see the number 128. Can 128 be taking away from 192? Of course it can, that means that bit in on. Then subtract 128 from 192 which leaves us with 64. The chart now looks like this:

Decimal 128 64 32 16 8 4 2 1
Bits 1

Can we take 64 away now? Yes, we can. So the next bit is also on. and we're left with zero. Nothing can take away from zero so that means every other bit is 0.

Decimal 128 64 32 16 8 4 2 1
Bits 1 1 0 0 0 0 0 0

You have now converted the number 192 to binary: 11000000. Then continue with the second octet, 168 and convert it to binary. After all numbers to binary, you'll end up with 11000000.10101000.00000001.00101100.

The subnet mask

The subnet mask is a weird ip address. In your home network, your subnet mask is probably 255.255.255.0. If you convert the subnet mask to binary, you will get 11111111.11111111.11111111.00000000. What does that mean? The 1's are the network bits and tell us how big the network is. The 0's are the host bits. Hosts are the devices connected to your network. The amount of host bits tell us how many devices are possible to connect to the network. In our case, with eight 0's, that means we have 256 possible ip addresses in the network. (minus 2 because the first and last ip address are reserved).

Subnetting

What is subnetting? Subnetting is changing the subnet mask so you can have more hosts in the network and/or dividing the network in smaller networks. That is possible by changing the amount of 1's and 0's in the subnet mask (in binary form). If you want more hosts than 254 in your network. Let's say 1000. The formula for how many possible hosts per bit is 2^(number of bits) - 2. If you need 1000 hosts, that means you need 2 more host bits ((2^10)-2 = 1022). Now replace two 1's from the right side to a 0. The new subnet mask would be 11111111.11111111.11111100.00000000. When we convert back to decimal, you get: 255.255.252.0. That is our new subnet mask for 1022 possible hosts.

But what if you need to slice the network into smaller networks? We can do that too! In this example, we will divide the network into 4 sub networks. The ip address is 192.168.1.0 and the subnet mask is 255.255.255.0. First write down the subnet mask into binary: 11111111.11111111.11111111.00000000. To create 4 networks we need more network bits. How many? Well, take this chart from before and double the decimals:

Decimal 256 128 64 32 16 8 4 2
Bits

We check the 4 and count how many bits it takes to get there (from the right). It takes 2 bits. That means we need 2 more network bits in our subnet mask. That would look like this: 11111111.11111111.11111111.11000000. Converting to decimal, gives us 255.255.255.192 or in CIDR notation: 192.168.1.0/26. To build our table of network ranges, we need to find the increment. It is very easy! Place the subnet mask into this chart:

Decimal 128 64 32 16 8 4 2 1
Bits 1 1 0 0 0 0 0 0

See the last network bit and check the corresponding decimal. In our example 64. That is our increment. Now we can build our table of network ranges:

# Start End
1 192.168.1.0 192.168.1.63
2 192.168.1.64 192.168.1.127
3 192.168.1.128 192.168.1.191
4 192.168.1.192 192.168.1.255

And that is it! You now know how to subnet your network. Creating a bigger network or dividing a network into smaller pieces.