IPv4, in short, is an addressing system that allows devices connected to the internet (computers, phones, etc.) to recognize each other. Let's now examine the structure of this addressing.
- An IPv4 address is a 32-bit number consisting of 4 sections (octets) of 8 bits each. (8 bits = 1 byte)
- For human readability, these bits are converted into decimal numbers from 0-255, separated by dots. This is called Dotted-Decimal Notation.
- Example:
11000000.10101000.00000001.00000001
(binary - what computers understand) =192.168.1.1
(decimal - what we understand)
- Example:
- We perform this conversion using the following logic.
- IP Address:
192.168.1.1
- Method:
Each bit represents a power of 2. The decimal equivalents of the 8 bits within an octet are as follows:
To get the number we have, we find which values in the table we need to "use". We write 1 under each value we use and 0 under those we don't.128(1) - 64(1) - 32(0) - 16(0) - 8(0) - 4(0) - 2(0) - 1(0)
which means 128+64=192
128(1) - 64(0) - 32(1) - 16(0) - 8(1) - 4(0) - 2(0) - 1(0)
which means 128+32+8=168
- IP Address:
Network and Host ID
Every IPv4 address consists of two fundamental parts. A Network Mask is used to separate these parts.
- Network ID: Specifies which network the device is on. It's like the street name. The
1
s in the network mask represent this part. - Host ID: Identifies a specific device on that network. It's like the house number. The
0
s in the network mask represent this part.
Example:
- IP Address:
192.168.1.10
- Network Mask:
255.255.255.0
, The binary equivalent of this mask is:11111111.11111111.11111111.00000000
- Analysis: This mask indicates that the first three octets (the first 24 bits) are the Network ID, and the last octet (the last 8 bits) is the Host ID.
- Network ID:
192.168.1.0
- Host ID:
10
- Network ID:
CIDR Notation
This provides a more flexible way to express the network mask we just mentioned by appending a / (slash) and the number of bits representing the network ID to the end of the IP address.
192.168.1.10/24
β Indicates that the first 24 bits are the network ID (i.e., the255.255.255.0
mask).10.50.0.0/8
β Indicates that the first 8 bits are the network ID (i.e., the255.0.0.0
mask).
Special-Purpose IP Addresses
Certain IP addresses and ranges are reserved for special tasks and cannot be assigned to a normal device.
- Network Address: Defines the network itself. All bits in the host ID portion are
0
(e.g.,192.168.1.0/24
). - Broadcast Address: Used to send data to all devices on a network. All bits in the host ID portion are
1
(e.g.,192.168.1.255/24
). - Local Loopback: The address
127.0.0.1
is used for a device to communicate with itself. It is generally used for testing purposes. - Private IP Ranges: These are addresses that cannot be routed on the public internet and are only for use on local networks (home, office, etc.).
10.0.0.0
-10.255.255.255
(10.0.0.0/8
)172.16.0.0
-172.31.255.255
(172.16.0.0/12
)192.168.0.0
-192.168.255.255
(192.168.0.0/16
)
Subnetting
This is the process of dividing a large IP network into smaller, more efficient, and manageable Subnets. Let's walk through an example.
Step 1: Calculating Basic Information
- IP Address:
192.168.12.140/26
- CIDR:
/26
- Network Mask:
255.255.255.192
- Binary Mask:
11111111.11111111.11111111.11000000
Now, let's find the fundamental addresses of the subnet with this information:
- Network Address:
- Found by setting all bits in the Host Portion of the IP address to
0
. - IP (Binary):
11000000.10101000.00001100.10
001100
- Mask (Binary):
11111111.11111111.11111111.11
000000
- Result (Binary):
11000000.10101000.00001100.10
000000
- Result (Decimal):
192.168.12.128
- Found by setting all bits in the Host Portion of the IP address to
- Broadcast Address:
- Found by setting all bits in the Host Portion of the IP address to
1
. - Result (Binary):
11000000.10101000.00001100.10
111111
- Result (Decimal):
192.168.12.191
- Found by setting all bits in the Host Portion of the IP address to
- Usable IP Range:
- The Network and Broadcast addresses cannot be assigned to devices. All addresses in between are usable.
- Result:
192.168.12.129
-192.168.12.190
- Number of Usable Hosts:
- A
/26
mask leaves32 - 26 = 6
bits for the host portion. The total number of IPs is2^6 = 64
. - Result:
64 - 2
(Network and Broadcast Address) = 62 usable IPs.
- A
Step 2: Dividing the Network into Smaller Subnets
Let's divide the existing 192.168.12.128/26
network into 4 equal parts.
- Finding the Required Number of Bits: To create 4 subnets, since
2^2 = 4
, we need to "borrow" 2 more bits for the network mask.- The rule of thumb is: If you borrow n bits, you create 2βΏ new subnets.
Exponent Value 2 ^0 - 00000000 - Full Network = 1 2 ^1 - 10000000 - 2 Networks = 2 2 ^2 - 11000000 - 4 Networks = 4 2 ^3 - 11100000 = 8 2 ^4 - .... = 16 2 ^5 = 32 2 ^6 = 64 2 ^7 = 128 2 ^8 = 256 - Determining the New Subnet Mask: Our current mask was
/26
. We find the new mask by adding 2 more bits./26
+ 2 bits =/28
(or255.255.255.240
)
- Calculating the New Subnets: When our large block of 64 addresses is divided by 4, each new subnet will have 16 addresses (
64 / 4 = 16
). Starting from192.168.12.128
, we proceed in increments of 16:
- 1st Subnet:
192.168.12.128/28
(Network: .128, Broadcast: .143, Usable: .129 - .142) - 2nd Subnet:
192.168.12.144/28
(Network: .144, Broadcast: .159, Usable: .145 - .158) - 3rd Subnet:
192.168.12.160/28
(Network: .160, Broadcast: .175, Usable: .161 - .174) - 4th Subnet:
192.168.12.176/28
(Network: .176, Broadcast: .191, Usable: .177 - .190)
Quick Subnet Calculation Method
More practical methods can be used instead of complex binary calculations.
- Finding the Relevant Octet: Determine which octet you are working on by looking at the CIDR mask.
/8
-/15
β 2nd octet/16
-/23
β 3rd octet/24
-/30
β 4th octet
By remembering these four numbers, we will determine which octet of the IP Address can change.- For example, given the network address
192.168.1.1/25
, it is immediately clear that192.168.2.4
is not on the same network because a/25
subnet means only the fourth octet can change.
- Finding the Block Sizes: Find the increment interval for subnets in the relevant octet.
- Formula:
256 - (Mask Value in the Relevant Octet)
- Example (
for /26
): Mask is255.255.255.192
. The value of the relevant octet (4th) is192
.- Block Size:
256 - 192 = 64
. This indicates that the network addresses will increment by 64 (0, 64, 128, 192).
- Block Size:
- Example (
for /28
): Mask is255.255.255.240
. The value of the relevant octet (4th) is240
.- Block Size:
256 - 240 = 16
. This indicates that the network addresses will increment by 16 (0, 16, 32, ... 128, 144, 160...).
- Block Size:
- Formula:
Thanks for reading our article, you can share your thoughts in the comments. Have a great day...
Comments
Loading comments...