Skip to main content

Command Palette

Search for a command to run...

3 day ip address

Happy Star Wars Day, everyone! I am so thrilled to have you join us for a geek-out about Star Wars and binary numbering.

Today, I would like to share with you a three-step process for quickly identifying the network of a given IP address and subnet mask. Within a minute, you can say, "Oh yeah, it lives on this network." This will be tremendously helpful for troubleshooting and network design. When you take a network address space and chop it up, you need to know what IP addresses to assign, which addresses are valid, and so on.

IPv4 Addressing Overview

An IPv4 address is 32 bits long and typically written in a format called "dotted decimal notation. " In this format, the 32-bit address is divided into four groups of eight bits (octets), each converted to a decimal number and separated by dots. For example, address 10.1.2.3 consists of four octets.

Each device in a network has a unique address that consists of two parts: the network portion and the host portion. The dividing line between them is determined by the subnet mask.

A subnet mask, such as /24, tells us how many bits belong to the network portion. If an address has a /24 mask, it means the first 24 bits are for the network, and the remaining 8 bits are for hosts.

IPv4 Address as a 32-bit Number

An IPv4 address consists of 32 bits. This means that the entire IP address is made up of 32 binary digits (bits), which can either be 0 or 1.

Example of a 32-bit IPv4 Address in Binary:

11000000 10101000 00000001 00001010

This is a raw IPv4 address in binary form.


2. IPv4 is Divided into 4 Octets

  • Each octet consists of 8 bits.

  • Since IPv4 has 32 bits, we divide it into 4 groups of 8 bits (4 octets).

Visual Breakdown:

Octet 1Octet 2Octet 3Octet 4
11000000101010000000000100001010
(8 bits)(8 bits)(8 bits)(8 bits)

Each octet is separated by a dot (.) in the final representation.


3. Converting Each Octet from Binary to Decimal

Each 8-bit octet represents a decimal number (0 to 255).

To convert binary to decimal, we use positional values:

Binary Position (Power of 2)1286432168421
Octet 1 (11000000)11000000
Octet 2 (10101000)10101000
Octet 3 (00000001)00000001
Octet 4 (00001010)00001010

Now, we calculate the decimal value of each octet:

  • Octet 1: 11000000 β†’ 192 (128 + 64)

  • Octet 2: 10101000 β†’ 168 (128 + 32 + 8)

  • Octet 3: 00000001 β†’ 1 (only 1)

  • Octet 4: 00001010 β†’ 10 (8 + 2)

So, our IPv4 address in decimal format is:

192.168.1.10

Structure of an IP Address

  • An IPv4 address consists of 4 octets (or bytes).

  • Each octet contains 8 bits (1 byte).

  • The total size of an IPv4 address is 4 bytes (32 bits).

πŸ“Œ Example of an IPv4 Address:

192      .168      .1        .10
11000000.10101000.00000001.00001010
  • Octet 1 β†’ 192

  • Octet 2 β†’ 168

  • Octet 3 β†’ 1

  • Octet 4 β†’ 10

Each octet ranges from 0 to 255 because:

  • The maximum 8-bit binary number is 11111111 (255 in decimal).

  • The minimum 8-bit binary number is 00000000 (0 in decimal).


How to Count Octets

  1. Break the IP address into 4 groups separated by dots.

  2. Each group is 8 bits (one octet).

  3. Number the octets from left to right.

πŸ“Œ Example with Binary:

11000000.10101000.00000001.00001010
192      .168      .1        .10
  • First Octet β†’ 11000000 = 192

  • Second Octet β†’ 10101000 = 168

  • Third Octet β†’ 00000001 = 1

  • Fourth Octet β†’ 00001010 = 10

πŸ“ Important:

  • 1 octet = 8 bits

  • 4 octets = 32 bits (IPv4 address)


Subnet Mask and Counting Network Bits

The subnet mask determines which octets are for the network and which are for the host.

Example 1: /24 Subnet Mask (255.255.255.0)

192      .168      .1        .10
11000000.10101000.00000001.00001010

Subnet Mask:

255      .255      .255      .0
11111111.11111111.11111111.00000000
  • Network Portion: First 24 bits (3 full octets)

  • Host Portion: Last 8 bits (1 octet)

Octet NumberBits UsedFunction
1st Octet (192)8Network
2nd Octet (168)8Network
3rd Octet (1)8Network
4th Octet (10)8Host

Result:

  • Network bits: 24

  • Host bits: 8


Example 2: /16 Subnet Mask (255.255.0.0)

172      .16       .5        .100
10101100.00010000.00000101.01100100

Subnet Mask:

255      .255      .0        .0
11111111.11111111.00000000.00000000
  • Network Portion: First 16 bits (2 full octets)

  • Host Portion: Last 16 bits (2 octets)

Octet NumberBits UsedFunction
1st Octet (172)8Network
2nd Octet (16)8Network
3rd Octet (5)8Host
4th Octet (100)8Host

Result:

  • Network bits: 16

  • Host bits: 16


Example 3: /30 Subnet Mask (255.255.255.252)

10       .1        .1        .2
00001010.00000001.00000001.00000010

Subnet Mask:

255      .255      .255      .252
11111111.11111111.11111111.11111100
  • Network Portion: First 30 bits (almost 4 full octets)

  • Host Portion: Last 2 bits (part of the 4th octet)

Octet NumberBits UsedFunction
1st Octet (10)8Network
2nd Octet (1)8Network
3rd Octet (1)8Network
4th Octet (2)6 (Network) / 2 (Host)Mixed

Result:

  • Network bits: 30

  • Host bits: 2

Since only 2 bits are left for the host:

  • 2^2 - 2 = 2 usable hosts

  • Perfect for point-to-point links between routers.


Step 4: How to Calculate Hosts

The number of hosts in a subnet is determined by the remaining bits after the network portion.

Formula for Usable Hosts:

Usable Hosts=2Host Bitsβˆ’2\text{Usable Hosts} = 2^{\text{Host Bits}} - 2

(Subtracting 2 for network and broadcast addresses.)

Subnet MaskHost BitsUsable Hosts
/8 (255.0.0.0)2416,777,214
/16 (255.255.0.0)1665,534
/24 (255.255.255.0)8254
/30 (255.255.255.252)22

Step 5: How to Calculate Network Addresses

To find subnets:

  1. Identify the "Interesting Octet"

    • The last octet in the subnet mask with a 1 in binary.
  2. Find the Block Size

    • Block Size = 256 - Subnet Value in Interesting Octet
  3. Count Networks Using Block Size

Example: Find the Subnet for 192.168.1.50/26

  • Subnet Mask: 255.255.255.192 (/26 = 26 network bits)

  • Interesting Octet: 4th Octet

  • Block Size: 256 - 192 = 64

  • Subnet Ranges: Start at 0 and count in steps of 64:

    • 192.168.1.0 - 192.168.1.63

    • 192.168.1.64 - 192.168.1.127

    • 192.168.1.128 - 192.168.1.191

    • 192.168.1.192 - 192.168.1.255

Find where 192.168.1.50 fits:

  • It falls in 192.168.1.0/26.

Binary Numbering

Understanding binary is essential for subnetting. In a base-2 numbering system, we only use 1s and 0s. Each bit position represents a power of two.

To convert binary to decimal:

  1. Write down the binary number.

  2. Assign powers of two from right to left (1, 2, 4, 8, 16, 32, 64, 128).

  3. Add up the values where there is a 1.

Example: 11001011

  • 128 + 64 + 0 + 0 + 8 + 0 + 2 + 1 = 203

To convert decimal to binary:

  1. Start from the leftmost bit.

  2. Determine if the decimal number is greater than or equal to each power of two.

  3. Subtract the power of two when used and mark a 1, otherwise, mark a 0.

Example: 167

  • 128 (yes) β†’ 1

  • 39 remaining β†’ 32 (yes) β†’ 1

  • 7 remaining β†’ 4 (yes) β†’ 1

  • 3 remaining β†’ 2 (yes) β†’ 1

  • 1 remaining β†’ 1 (yes) β†’ 1

Binary result: 10100111


Subnetting Basics

Subnetting allows us to divide a large network into smaller sub-networks, which helps improve performance, security, and efficient IP address usage.

Every IPv4 address belongs to one of five classes:

  • Class A: 1-126 (Default Mask: /8)

  • Class B: 128-191 (Default Mask: /16)

  • Class C: 192-223 (Default Mask: /24)

  • Class D: 224-239 (Multicast)

  • Class E: 240-255 (Experimental)

Private IP ranges that are not routable on the public internet:

  • 10.0.0.0/8

  • 172.16.0.0 - 172.31.255.255 /12

  • 192.168.0.0 - 192.168.255.255 /16


Subnet Calculations

To determine the number of subnets:

  • Formula: 2^S (where S = number of borrowed bits)

To determine the number of hosts per subnet:

  • Formula: 2^H - 2 (where H = number of host bits)

For example, applying a /27 subnet mask to a Class C network:

  • Subnet Mask: 255.255.255.224

  • Borrowed Bits: 3 (/24 to /27)

  • Number of Subnets: 2^3 = 8

  • Number of Hosts per Subnet: 2^5 - 2 = 30


IPv6 Addressing Overview

IPv6 uses 128-bit addresses written in hexadecimal notation, divided into eight groups (quartets) separated by colons.

Example:
2001:0db8:85a3:0000:0000:8a2e:0370:7334

Rules for abbreviation:

  1. Omit leading zeros in each quartet.

    • 0004 β†’ 4
  2. Use :: to replace consecutive all-zero quartets (only once per address).

    • 2001:0db8:0000:0000:0000:0000:1428:57ab
      β†’ 2001:db8::1428:57ab

Hexadecimal Conversions

Hexadecimal (base-16) uses values 0-9 and A-F.
Each hex digit represents 4 bits.

Example:

  • Decimal 241 β†’ Binary 11110001 β†’ Hex 0xF1

  • Hex 0xBC β†’ Binary 10111100 β†’ Decimal 188

What is Subnetting?

Subnetting is the process of dividing a larger network into smaller, more manageable subnetworks or subnets. By breaking down a network, subnetting helps organize and efficiently allocate IP addresses, preventing waste of IP resources.

It enhances network performance by reducing traffic congestion and improves security by isolating different parts of a network.

Subnetting also allows network administrators to better manage and control access within different areas of a network, making it easier to troubleshoot and maintain.

Each subnet operates independently, yet remains part of the larger network, ensuring efficient communication between devices.

IP Addresses & Subnet Masks

An IP address is a unique numerical label assigned to each device connected to a network, allowing it to communicate with other devices. It's essentially the digital address that helps identify and locate devices within a network or across the internet.

IP addresses come in two versions:

  • IPv4, which consists of four sets of numbers.

  • IPv6, which uses a longer format to accommodate the growing number of devices online.

A subnet mask is a crucial companion to IP addresses. It determines how the address is split between the network portion and the host portion.

A subnet mask consists of a sequence of numbers, typically written in the same format as an IP address. It tells the device how much of the IP address belongs to the network and how much is reserved for the individual device.

IP Address Classes

Expanding on IP addresses, let's take a look at IP address classes.

IP address classes categorize IP addresses based on their range and intended use, providing a structured approach to allocating addresses within a network.

The primary classes are Class A, B, C, D, and E:

  • Class A – For very large networks (up to 16 million hosts), used by major organizations and ISPs.

  • Class B – Supports medium-sized networks (up to 65,000 hosts), ideal for universities and larger businesses.

  • Class C – Used for small networks (up to 254 hosts), common in smaller offices and home networks.

  • Class D – Reserved for multicast groups, allowing a single packet to be sent to multiple hosts at once (used in streaming and conferencing).

  • Class E – Reserved for experimental and research purposes.

The range between 126.0.0.0 and 128.0.0.0 includes IP addresses that are part of Class A but are primarily reserved for loopback addresses, allowing applications to communicate with the host without requiring an external network.

The most commonly used address in this range is 127.0.0.1, often referred to as localhost.

Subnetting Calculation

Now let's take a look at basic subnetting calculations.

For subnetting, we need the original IP address and the subnet mask.

Suppose we have the IP address 192.168.1.0 and the subnet mask 255.255.255.0.

To begin, we convert the subnet mask into binary. The subnet mask in binary reveals the division between the network and host portions.

In this case, the subnet mask translates to 24 ones and 8 zeroes. The number of zeroes in the subnet mask determines the number of possible hosts.

The formula to calculate the number of possible addresses in a subnet is:
2ⁿ, where n is the number of bits allocated for the host portion.

In this example, there are 8 zeroes, so the number of possible addresses is 2⁸ = 256.

However, not all of these addresses can be assigned to devices.

  • The first address is the network ID, which identifies the subnet itself.

  • The last address is the broadcast address, used to send data to all devices in the subnet.

This leaves us with 254 usable IP addresses.

Additionally, the more zeroes in the subnet mask, the more hosts can be supported. Conversely, a subnet mask with more ones means fewer hosts but more subnets.

The number of subnets can be calculated using the formula 2ᡐ, where m is the number of bits borrowed from the host portion to create subnets.

Reading & Interpreting Subnetting

Reading and interpreting subnetting requires identifying key elements like:

  • Network Address

  • Broadcast Address

  • Range of Usable IP Addresses

A common way to represent this is through CIDR (Classless Inter-Domain Routing) notation, which combines the IP address with a suffix that indicates the number of network bits in the subnet mask.

For example:
An IP address of 192.168.10.15/24 tells us that the first 24 bits belong to the network portion, leaving 8 bits for hosts.

Common Subnetting Scenarios

Some common subnetting scenarios include:

  • Dividing a large corporate network into smaller subnets to enhance security and reduce congestion.

  • Allocating subnets based on geographic locations, allowing remote offices to communicate effectively.

  • Implementing subnets to accommodate growth, making it easy to create new subnets without restructuring the network.

  • ISPs managing their IP address space effectively to distribute ranges to customers while optimizing utilization.

Classful vs Classless Subnetting

Subnetting can be classful or classless:

  • Classful Subnetting follows fixed IP address classes (A, B, C, etc.), which limits flexibility.

  • Classless Subnetting (CIDR) allows administrators to define subnet masks freely, optimizing IP address usage and routing efficiency.

Pitfalls & Best Practices

When managing subnetting, keep these in mind:
βœ” Document subnet configurations to avoid confusion.
βœ” Plan for future growth to prevent readdressing issues.
βœ” Use a hierarchical addressing scheme to improve routing.
βœ” Regularly review and update address assignments to avoid conflicts.