What is subnetting And How it works??

Subnet

       The main purpose of subnetting is to help relieve network congestion. Congestion used to be a bigger problem than it is today because it was more common for networks to use hubs than switches. When nodes on a network are connected through a hub, the entire network acts as a single collision domain.



Partitioning a single network can help relieve network congestion and increase security

If you work inside a large organisation or business, particularly one spread across multiple branches, it's highly likely that it deploys a subnet.
A subnetting, or subnetworking, is the process of splitting a single large network into two or more strands. This means that an otherwise mammoth and unwieldy network can be subdivided into smaller, more localised networks.

First, a look at IP addresses

IP addresses are comprised of a 32-bit number with values ranging from zero to 4294967295, split into four octets. In order for it to be read, each octet (a unit consisting of eight bits) is converted to decimal, which are then separated by a single dot, creating the recognisable IP format. Using this method, it's possible to create 4.3 billion unique IP addresses.
IPs also consist of two fields: the Network Prefix (or ID) and the Host ID. The point at which these two are separate depends on the class in which the address is placed. There are five different classes of networks, which run from A to E - the majority of IP addresses are in the A to C class, with D and E being reserved.
Class A networks use a default subnet mask of 255.0.0.0 and have 0-127 as their first octet. Class B networks use a default subnet mask of 255.255.0.0 and have 128-191 as their first octet. Class C networks use a default subnet mask of 255.255.255.0 and have 192-223 as their first octet.
A Class A, B, or C TCP/IP network can be further divided, or subnetted, by an organisation's IT administrator.

Why use subnetting?

When the IP system was first developed, it became clear that although it was now incredibly easy to find a target network, it was relatively difficult to route a data packet to the right machine on that network. This is made even more difficult when networks reach the scale required to support an organisation, where network performance starts to become an issue.
By breaking the network up into smaller parts, subnets help alleviate this network congestion, however, it also serves to redistribute the network's capacity and allow data packets to flow directly to the target destination without having to squeeze through a single bottleneck.
An organisation can use IP subnets to divide larger networks for logical reasons (firewalls, etc), or physical requirements (smaller broadcast domains, etc). In other words, routers use subnets to make routing choices.
Subnetting can also improve network security. With a division between subnets, organisations can control who has access to what. With subnets, security incidents can be better contained.
Image result for what is subnetting

What is a subnet mask?

As with an IP address, a subnet mask comprises four bytes (32 bits) and is written in the same notation as an IP address, typically this is 255.255.255.0. For TCP/IP to work, you need a subnet mask.
The subnet mask complements an IP address and by applying it to the IP address and it determines what subnet an IP address belongs to. An IP address has two components, the network address and the host address. Subnetting further divides the host part of an IP address into a subnet and host address if additional subnetworks are needed. In effect, it masks an IP address and divides the IP address into network address and host address.

What is a default gateway?

When a computer on one network needs to communicate with a computer on another, it uses a router. A router specified on a host, which connects the host's subnet to other networks, is called a default gateway. This passes traffic on one subnet to devices on other subnets. This gateway often connects the local subnet to the internet.

 How it Works
 

Calculating the Netmask Length (also called a prefix):

Convert the dotted-decimal representation of the netmask to binary. Then, count the number of contiguous 1 bits, starting at the most significant bit in the first octet (i.e. the left-hand-side of the binary number).
255.255.248.0   in binary: 11111111 11111111 11111000 00000000
                           -----------------------------------
                           I counted twenty-one 1s             -------> /21
The prefix of 128.42.5.4 with a 255.255.248.0 netmask is /21.

Calculating the Network Address:

The network address is the logical AND of the respective bits in the binary representation of the IP address and network mask. Align the bits in both addresses, and perform a logical AND on each pair of the respective bits. Then convert the individual octets of the result back to decimal.
Logical AND truth table:





Logical AND
128.42.5.4      in binary: 10000000 00101010 00000101 00000100
255.255.248.0   in binary: 11111111 11111111 11111000 00000000
                           ----------------------------------- [Logical AND]
                           10000000 00101010 00000000 00000000 ------> 128.42.0.0
As you can see, the network address of 128.42.5.4/21 is 128.42.0.0

Calculating the Broadcast Address:

The broadcast address converts all host bits to 1s...
Remember that our IP address in decimal is:
128.42.5.4      in binary: 10000000 00101010 00000101 00000100
The network mask is:
255.255.248.0   in binary: 11111111 11111111 11111000 00000000
This means our host bits are the last 11 bits of the IP address, because we find the host mask by inverting the network mask:
Host bit mask            : 00000000 00000000 00000hhh hhhhhhhh
To calculate the broadcast address, we force all host bits to be 1s:
128.42.5.4      in binary: 10000000 00101010 00000101 00000100
Host bit mask            : 00000000 00000000 00000hhh hhhhhhhh
                           ----------------------------------- [Force host bits]
                           10000000 00101010 00000111 11111111 ----> 128.42.7.255

Calculating subnets:

You haven't given enough information to calculate subnets for this network; as a general rule you build subnets by reallocating some of the host bits as network bits for each subnet. Many times there isn't one right way to subnet a block... depending on your constraints, there could be several valid ways to subnet a block of addresses.
Let's assume we will break 128.42.0.0/21 into 4 subnets that must hold at least 100 hosts each...
subnetting
In this example, we know that you need at least a /25 prefix to contain 100 hosts; I chose a /24 because it falls on an octet boundary. Notice that the network address for each subnet borrows host bits from the parent network block.

Finding the required subnet masklength or netmask:

How did I know that I need at least a /25 masklength for 100 hosts? Calculate the prefix by backing into the number of host bits required to contain 100 hosts. One needs 7 host bits to contain 100 hosts. Officially this is calculated with:
Host bits = Log2(Number-of-hosts) = Log2(100) = 6.643
Since IPv4 addresses are 32 bits wide, and we are using the host bits (i.e. least significant bits), simply subtract 7 from 32 to calculate the minimum subnet prefix for each subnet... 32 - 7 = 25.

The lazy way to break 128.42.0.0/21 into four equal subnets:

Since we only want four subnets from the whole 128.42.0.0/21 block, we could use /23 subnets. I chose /23 because we need 4 subnets... i.e. an extra two bits added to the netmask.
This is an equally-valid answer to the constraint, using /23 subnets of 128.42.0.0/21...
subnetting, 2nd option

Calculating the host number:

This is what we've already done above... just reuse the host mask from the work we did when we calculated the broadcast address of 128.42.5.4/21... This time I'll use 1s instead of h, because we need to perform a logical AND on the network address again.
128.42.5.4      in binary: 10000000 00101010 00000101 00000100
Host bit mask            : 00000000 00000000 00000111 11111111
                           ----------------------------------- [Logical AND]
                           00000000 00000000 00000101 00000100 -----> 0.0.5.4

Calculating the maximum possible number of hosts in a subnet:

To find the maximum number of hosts, look at the number of binary bits in the host number above. The easiest way to do this is to subtract the netmask length from 32 (number of bits in an IPv4 address). This gives you the number of host bits in the address. At that point...
Maximum Number of hosts = 2**(32 - netmask_length) - 2
The reason we subtract 2 above is because the all-ones and all-zeros host numbers are reserved. The all-zeros host number is the network number; the all-ones host number is the broadcast address.
Using the example subnet of 128.42.0.0/21 above, the number of hosts is...
Maximum Number of hosts = 2**(32 - 21) - 2 = 2048 - 2 = 2046

Finding the maximum netmask (minimum hostmask) which contains two IP addresses:

Suppose someone gives us two IP addresses and expects us to find the longest netmask which contains both of them; for example, what if we had:
  • 128.42.5.17
  • 128.42.5.67
The easiest thing to do is to convert both to binary and look for the longest string of network-bits from the left-hand side of the address.
128.42.5.17     in binary: 10000000 00101010 00000101 00010001
128.42.5.67     in binary: 10000000 00101010 00000101 01000011
                           ^                           ^     ^
                           |                           |     |
                           +--------- Network ---------+Host-+
                             (All bits are the same)    Bits
In this case the maximum netmask (minimum hostmask) would be /25
NOTE: If you try starting from the right-hand side, don't get tricked just because you find one matching column of bits; there could be unmatched bits beyond those matching bits. Honestly, the safest thing to do is to start from the left-hand side.



Table for Better Understanding 
Image result for subnet


Comments

Popular posts from this blog

Windows Defender

HirenBoot Windows Recovery Tool

Sign Into OneDrive