What is Subnetting (and How to Subnet IPv4 Network)?
In this article we’ll explain basics about IP addresses, subnet masks and subnets. If you use Windows OS and you enter ipconfig
in Command Prompt chances are that somewhere in the output you’ll see something like:
IPv4 Address. . . . . . . . . . . : 192.168.0.11
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1
From the given output we can conclude few things:
- IP address of the computer (host) is 192.168.0.11
- Network address is 192.168.0.0
- Network can have 254 hosts
- Last host in the given network will have IP address 192.168.0.254
- …
So, how exactly do we know about the above and what do they mean in the first place?
What is IPv4 address?
Every device in a network must be uniquely identified in order to be able to communicate with other devices in other networks and Internet. Unique identifier for the device in the network is its IP address.
From output above we can see that IP address is 192.168.0.11, so IP address is group of four decimal numbers separated by dots. Every number is between 0 and 255. IP address is divided in two parts:
- Network part of IP address
- Host part of IP address
In our example network part is 192.168.0
and host part is .11
In given example host part can be between 1 and 254. Next logical question is how we decide what is network part and what is host part? For that purpose subnet mask is used.
What is subnet mask?
Subnet mask hides (or masks) the network part IP address and shows only the host part as the device identifier. In our example subnet mask 255.255.255.0 means that first 3 numbers of IP address are network part and last number is host (device) part/identifier. For example if subnet mask is 255.255.0.0 that means first 2 numbers of IP address are network part and last 2 numbers are host part.
What is Subnetting?
Subnetting is procedure of dividing a network into two or more smaller (sub)networks called subnets. To fully understand subnetting we must know that computers and network devices use binary number system for communication. With that being said our IP address and subnet mask would be as follows:
IP address: 192.168.0.11 (Dec) = 11000000 10101000 00000000 00001011 (Bin)
Subnet mask: 255.255.255.0 (Dec) = 11111111 11111111 11111111 00000000 (Bin)
When we write IP address in binary form we can see that IPv4 address has 32 bits. Another way of saying that subnet mask is 255.255.255.0 is just to write it as /24. This means that first 24 bits are network address and last 8 bits are host address. We already told that network address is 192.168.0.0 but how do we calculate that? To get network address we do logical AND operation between host address and its subnet mask, so:
11000000 10101000 00000000 00001011 & 11111111 11111111 11111111 00000000 = 11000000 10101000 00000000 00000000
In decimal, network address is 192.168.0.0/24
Network 192.168.0.0/24 uses last 8 bits for host address. With 8 bits we have 256 numbers from 0 to 255 (because 28=256). First address 192.168.0.0 is network address, last address 192.168.0.255 is called broadcast address. Those are two addresses we can’t use as addresses for hosts, reasons for that will be explained in some future article.
Let’s say we have company where we want to have 2 networks (subnets), first for PCs in wired network (LAN) and second for WiFi (WLAN). We will use network 192.168.0.0/24 and divide it in two smaller /25 networks:
First subnet parameters are as follows:
Network address:
192.168.0.0/25
Usable (host) addresses:
192.168.0.1 to 192.168.0.126
Broadcast address:
192.168.0.127
Subnet mask:
255.255.255.128
Second subnet parameters are as follows:
Network address:
192.168.0.128/25
Usable (host) addresses:
192.168.0.129 to 192.168.0.254
Broadcast address:
192.168.0.255
Subnet mask:
255.255.255.128
At the end /26 example is given, so try to figure out the rest of parameters yourself đŸ™‚