How To Subnet

In this tutorial, you will learn how to subnet a network in an easy way for beginners. Subnetting is designed for devices that are connected to a network and have to perform this operation repeatedly and quickly. Computers, routers, and smartphones operate in a binary world, reading, transmitting, and processing data with a binary representation. A host that sends packets on the wire is sending sets of signals that translate to binary data. Each binary digit is called a bit because a signal translates to 1 and a loss of signal translates to 0. In contrast to machines, humans use the decimal numbering system (not hackers and ninjas who use HEX all day, but all other humans) that uses ten digits 0-9 to represent any number. IPv4 addresses are written as four decimal numbers separated by periods (192.168.0.1). Each octet value can be between 0 and 255. Therefore, we need to learn how to convert a decimal number to a binary number. We can convert any number between 0-255 to 8 bits, also called a byte.

1st Octat/Byte 2nd Octat/Byte 3rd Octat/Byte 4th Octat/Byte
Binary 11000000 10101000 00000000 00000001
Decimal 192 168 0 1

Every bit in a byte has a different value, and the value doubles from right to left as it moves across the byte

Value 128 64 32 16 8 4 2 1
Bit 1 1 1 1 1 1 1 1

For example we will translate the number 125 to 8 binary bits. The algorithm is to start from the left and check if the number is equal or greater than the value. If the number is greater or equal we will subtract the value from the number and make the bit as 1, if the number is smaller we will mark the bit as 0. We will move to the next position till the end or till our number equal to zero and then we can mark all the other bits as 0. So let's start translating the number 125

Since 125 is not greater or equal to 128 we will mark the bit as 0

Value 128 64 32 16 8 4 2 1
Bit 0

125 is greater or equal to 64 so we will subtract 64 from 125 : 125-64 = 61 and mark the bit as 1

Value 128 64 32 16 8 4 2 1
Bit 0 1

61 is greater or equal to 32 so we will subtract 32 from 61: 61-32 = 29 and mark the bit as 1

Value 128 64 32 16 8 4 2 1
Bit 0 1 1

29 is greater or equal to 16 so we will subtract 16 from 29: 29-16 = 13 and mark the bit as 1

Value 128 64 32 16 8 4 2 1
Bit 0 1 1 1

13 is greater or equal to 8 so we will subtract 8 from 13: 13-8 = 5 and mark the bit as 1

Value 128 64 32 16 8 4 2 1
Bit 0 1 1 1 1

5 is greater or equal to 4 so we will subtract 4 from 5: 5-4 = 1 and mark the bit as 1

Value 128 64 32 16 8 4 2 1
Bit 0 1 1 1 1 1

1 is not greater or equal to 2 so we will mark the bit as 0

Value 128 64 32 16 8 4 2 1
Bit 0 1 1 1 1 1 0

1 is greater or equal to 1 so we will subtract 1 from 1: 1-1 = 0 and mark the bit as 1

Value 128 64 32 16 8 4 2 1
Bit 0 1 1 1 1 1 0 1

After we finished we will copy the bits from the table. So the binary representation of 125 is 01111101. You can check our result by adding all the values which their bit set to 1. 64+32+16+8+4+1=125 Go ahead and try to translate some IPv4 address to binary, you can check your results with the Subnet Calculator Ninja

How To Subnet WordCloud

Another elementary building blocks of computing devices are logical gates, the one that we will need to use for subnetting operation is the logical gate AND (There are more logic gates that are out of this article scope). The AND gate takes two binary numbers (bits) as input and outputs one bit by the following rule: if the two bits are 1 the output will be 1, in any other case the output will be 0.

Bit 1 Bit 2 Output
0 0 0
0 1 0
1 0 0
1 1 1

After we understand how to translate decimal to binary and the AND gate logic we finally can start to calculate subnets, in following example we will use the IPv4 address 192.168.0.100 and the subnet mask 255.255.255.224

First we need to translate them to binary:

IP Address 11000000.10101000.00000000.01100100
Subnet mask 11111111.11111111.11111111.11100000

Next we will run the AND gate on the binary bits to get the network address

IP Address 11000000.10101000.00000000.01100100
Subnet mask 11111111.11111111.11111111.11100000
Network Address 11000000.10101000.00000000.01100000

Now let's translate the binary network address to decimal, we will use the same way as we did to check the address translation from decimal to binary for every octets.

First octets: 11000000

Value 128 64 32 16 8 4 2 1
Bit 1 1 0 0 0 0 0 0

Calculating the values of the bits that sets to 1 : 128+64=192 the first octet equals to 192

Second octets: 10101000

Value 128 64 32 16 8 4 2 1
Bit 1 0 1 0 1 0 0 0

Calculating the values of the bits that sets to 1 : 128+32+8=168 the Second octet equals to 168

Third octets: 00000000

Value 128 64 32 16 8 4 2 1
Bit 0 0 0 0 0 0 0 0

There is no bits that sets to 1 so the octet equals to 0

Last octets: 01100000

Value 128 64 32 16 8 4 2 1
Bit 0 1 1 0 0 0 0 0

Calculating the values of the bits that sets to 1 : 64+32 = 96 the Second octet equals to 96

Adding the dots together, the network address is: 192.168.0.96

Quick tip: Because the first three octets of the subnet mask are equal to 255 or 11111111, you can see that the Network address is equal to the IP address in the first three octets. You can copy them and translate only the last octet. Go ahead and practice the method, check your results with our subnet Calculator Ninja