How to calculate subnets

Calculate Subnets

If you want to work with networks effectively, understanding subnetting is crucial! A subnet is a logical division of a larger IP network into smaller, more manageable segments. Think of it like dividing a large city into districts. Each district (subnet) can manage traffic and resources more efficiently within its boundaries.

An IP address, typically represented in decimal form like 192.168.1.100, consists of 4 octets (sections) with a total of 32 bits. Each octet can have a value ranging from 0 to 255. The IP address is further divided into two parts: the network address and the host address. The network address identifies the subnet to which a device belongs, while the host address identifies the specific device within that subnet.

Therefore, just by looking at an IP address, you cannot definitively determine whether two devices belong to the same network. This is where subnetting comes into play. Subnetting allows you to create subnetworks within a larger network, enabling better organization, security, and scalability.

Examples:

The IPs 192.168.1.100/24 and 192.168.1.101/25 do not belong to the same network, despite their format, because the network mask in the first case occupies 24 bits and in the second 25. Okay, this will make sense, hang on

In the first IP, the binary representation is:

IPv4 representation: 192.168.1.100/24

Binary representation: 11111111.11111111.11111111.00000000
IPv4 representation: 192.168.1.101/25

Binary representation: 11111111.11111111.11111111.10000000

If you check the representation of the octets and add them together, you will get 24 bits and 25 bits. This means that my network will be everything that is filled with 1 bits and my machines will be what is at 0 bits. In the first case, I can use 8 bits and in the second 7 bits.

Okay, with this I’ll go far… hang on, now let’s complicate things a bit

Okay, first things first. I didn’t mention that IPv4 addresses consist of 4 octets.

What are octets? An octet is a group of 8 bits, which is the basic unit of information storage in a computer. So, an IPv4 address is essentially made up of 4 groups of 8 bits each.

Let’s take a look at an example: 192.168.1.100. This IP address is divided into 4 sections, separated by periods. Each section represents one octet, and each octet can have a value ranging from 0 to 255.

In total, an IPv4 address has a length of 32 bits (4 octets x 8 bits/octet).

Let’s look into the examples using the concept of octets:

In the first example, we might see a usable range of 256 IP addresses. However, only 254 devices can actually connect to the network. This is because two IP addresses are reserved:

  • Broadcast Address: This address represents all devices on the subnet and is used for sending messages to every device at once.
  • Network Address: This address identifies the subnet itself and cannot be assigned to a specific device.

Similarly, in the second case, with a usable range of 128 IP addresses, only 126 machines can connect.

Now, you might be wondering, how do we configure a network without dealing with binary directly?

This is where the subnet mask comes in! The subnet mask, represented as 255.255.255.0 in the first example and 255.255.255.128 in the second, defines which part of the IP address belongs to the network (subnet) and which part identifies the specific device within that network.

Let’s break down calculating the subnet mask using one octet (section) as an example:

11111111.11111111.11111111.00000000

In this octet, all eight bits are set to 1 (represented by 11111111). This corresponds to a value of 255 in the network mask.

Each set bit (1) contributes a power of 2 to the final value:

1 bit = 128 | 1 bit = 64 | 1 bit = 32 | 1 bit = 16 | 1 bit = 8 | 1 bit = 4 | 1 bit = 2 | 1 bit = 1 <strong>SUM (128 + 64 + 32 + 16 + 8 + 4 + 2 + 1) = 255

Therefore, in this specific octet, all eight bits are used for the network portion of the IP address, leaving no bits for identifying individual devices within the subnet.

Now we can calculate the subnet of the IPs, let’s go

IPV4 representation: 192.168.1.100/24 

Binary representation: 11111111.11111111.11111111.00000000

Subnet calculation:  128+64+32+16+8+4+2+1 . 128+64+32+16+8+4+2+1 . 128+64+32+16+8+4+2+1 . 0+0+0+0+0+0+0+0 = 255.255.255.0
IPV4 representation: 192.168.1.101/25

Binary representation: 11111111.11111111.11111111.10000000 

Subnet calculation: 128+64+32+16+8+4+2+1 . 128+64+32+16+8+4+2+1 . 128+64+32+16+8+4+2+1 . 0+64+32+16+8+4+2+1 = 255.255.255.128

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *

pt_PT