First we need to understand that the subnetting process designed for devices that are connected to a network and need to do this operation many times and do it fast. Computing devices like computers, routers and smartphones live in a binary world, they read, transmit and process data with their binary representation for example a host that sends packets on the wire is sending sets of signals that translated to binary data. Signal translated to 1 and loss of signal translated to 0, every binary digit called a bit. Unlike the machines humans today mostly use the decimal numbering system (not hackers ninjas that use HEX all day, just all other humans) that use ten digits 0-9 to represent any number. IPv4 address writing format is four decimal numbers AKA octets separated by periods (192.168.0.1) every octet value can be in the range of 0 to 255. So we need to learn how to translate a decimal number to a binary number, we can translate any number in the rage of 0-255 to 8 bits AKA 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 the byte has a different value, the value doubles from the right position to the left

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

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