How to Configure and Verify IPv4 Addressing and Subnetting

How to Configure and verify IPv4 addressing and subnetting

Subnetting is often the single most feared topic for people studying networking — but it’s also one of the most important, practical skills you’ll use throughout your entire career. This article breaks IPv4 addressing and subnetting down from absolute first principles, with clear math, real configuration commands, and verification steps, so that by the end, subnetting feels like simple arithmetic rather than a mystery.

IPv4 Address Structure

An IPv4 address is 32 bits, usually written in dotted-decimal notation — four 8-bit numbers (octets), each ranging from 0–255, separated by dots:

192.168.1.10

Every IPv4 address is logically split into two parts:

  • Network portion — identifies which network the address belongs to
  • Host portion — identifies the specific device within that network

The subnet mask (or prefix length) determines exactly where the boundary between these two parts falls.

Subnet Masks and CIDR Notation

A subnet mask is also 32 bits, made up of consecutive 1s (network portion) followed by consecutive 0s (host portion).

Dotted DecimalBinaryCIDR Notation
255.255.255.011111111.11111111.11111111.00000000/24
255.255.255.12811111111.11111111.11111111.10000000/25
255.255.255.19211111111.11111111.11111111.11000000/26
255.255.0.011111111.11111111.00000000.00000000/16

CIDR (Classless Inter-Domain Routing) notation simply counts the number of 1 bits in the mask — /24 means the first 24 bits are network bits.

The Core Subnetting Formulas

QuestionFormula
How many total addresses in a subnet?2^(32 − prefix length)
How many usable host addresses?2^(32 − prefix length) − 2 (subtract network address and broadcast address)
How many subnets from borrowing “n” bits?2^n

The “−2” in the usable hosts formula accounts for:

  • The network address (all host bits = 0) — identifies the subnet itself, cannot be assigned to a device.
  • The broadcast address (all host bits = 1) — used to send a message to every device on that subnet, cannot be assigned to a device.

Worked Example: Subnetting 192.168.1.0/24 into Four Subnets

Requirement: Take 192.168.1.0/24 and split it into 4 equal subnets.

Step 1: Determine how many bits to borrow. We need at least 4 subnets, and 2^2 = 4, so we borrow 2 bits from the host portion.

Step 2: New prefix length = original /24 + 2 borrowed bits = /26.

Step 3: Calculate the block size (increment) using 2^(host bits remaining) = 2^(32−26) = 2^6 = 64.

Step 4: List the subnets, incrementing by 64 each time:

SubnetNetwork AddressFirst Usable HostLast Usable HostBroadcast Address
1192.168.1.0/26192.168.1.1192.168.1.62192.168.1.63
2192.168.1.64/26192.168.1.65192.168.1.126192.168.1.127
3192.168.1.128/26192.168.1.129192.168.1.190192.168.1.191
4192.168.1.192/26192.168.1.193192.168.1.254192.168.1.255

Each /26 subnet provides 2^6 − 2 = 62 usable host addresses.

Visualizing the Subnetting Process

flowchart TD
    A["Start: 192.168.1.0/24 (256 addresses)"] --> B["Need 4 subnets → borrow 2 bits"]
    B --> C["New prefix: /26 (64 addresses per subnet)"]
    C --> D["Subnet 1: 192.168.1.0/26"]
    C --> E["Subnet 2: 192.168.1.64/26"]
    C --> F["Subnet 3: 192.168.1.128/26"]
    C --> G["Subnet 4: 192.168.1.192/26"]

Variable Length Subnet Masking (VLSM)

Real networks rarely need equally sized subnets. VLSM allows different subnets to have different sizes, matching each subnet exactly to its actual host requirement — dramatically reducing wasted address space compared to fixed-size subnetting.

Worked VLSM Example

Requirement: From 192.168.1.0/24, create subnets for:

  • Sales department: 50 hosts
  • Engineering department: 20 hosts
  • A point-to-point router link: 2 hosts

Step 1: Sales (needs 50 hosts)

  • 2^6 − 2 = 62 usable hosts → requires a /26
  • Assign: 192.168.1.0/26 (range: .1–.62)

Step 2: Engineering (needs 20 hosts)

  • 2^5 − 2 = 30 usable hosts → requires a /27
  • Assign the next available block after Sales: 192.168.1.64/27 (range: .65–.94)

Step 3: Point-to-point link (needs only 2 hosts)

  • 2^2 − 2 = 2 usable hosts → requires a /30
  • Assign the next available block: 192.168.1.96/30 (range: .97–.98)
SubnetRequirementPrefix AssignedUsable Range
Sales50 hosts/26192.168.1.1 – .62
Engineering20 hosts/27192.168.1.65 – .94
Point-to-Point Link2 hosts/30192.168.1.97 – .98

Notice how VLSM avoids wasting an entire /26 (62 usable addresses) on a link that only ever needs 2 — a massive efficiency gain compared to fixed-length subnetting, especially at scale.

Cisco Configuration: Assigning IPv4 Addresses

Router(config)# interface GigabitEthernet0/0
Router(config-if)# ip address 192.168.1.1 255.255.255.192
Router(config-if)# no shutdown
Router(config-if)# description Sales VLAN Gateway
Router(config)# interface GigabitEthernet0/1
Router(config-if)# ip address 192.168.1.65 255.255.255.224
Router(config-if)# no shutdown
Router(config-if)# description Engineering VLAN Gateway
Router(config)# interface Serial0/0/0
Router(config-if)# ip address 192.168.1.97 255.255.255.252
Router(config-if)# no shutdown
Router(config-if)# description Point-to-point link to R2

Verification Commands

show ip interface brief

Quick overview of all interfaces, their IP addresses, and status:

Router# show ip interface brief
Interface              IP-Address      OK? Method  Status     Protocol
GigabitEthernet0/0      192.168.1.1     YES manual  up         up
GigabitEthernet0/1      192.168.1.65    YES manual  up         up
Serial0/0/0             192.168.1.97    YES manual  up         up

show ip interface

Full detail, including the exact subnet mask and broadcast address:

Router# show ip interface GigabitEthernet0/0
GigabitEthernet0/0 is up, line protocol is up
  Internet address is 192.168.1.1/26
  Broadcast address is 255.255.255.255
  Address determined by non-volatile memory

show running-config interface

Confirms the exact configured address and mask as entered:

Router# show running-config interface GigabitEthernet0/0
interface GigabitEthernet0/0
 description Sales VLAN Gateway
 ip address 192.168.1.1 255.255.255.192

Ping Test to Confirm Subnet Boundaries Work Correctly

Router# ping 192.168.1.62
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.62, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5)

A successful ping to .62 (the last usable host in the Sales /26 subnet) but failure pinging .63 (the broadcast address, which shouldn’t be assigned to any device) confirms correct subnet boundary understanding.

Linux Verification Example

$ ip addr add 192.168.1.65/27 dev eth0
$ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
    inet 192.168.1.65/27 brd 192.168.1.95 scope global eth0

Notice Linux automatically calculates and displays the correct broadcast address (192.168.1.95) for a /27 subnet — a great way to double-check your manual subnetting math.

Python Example: Automated Subnet Calculator

Manual subnetting math is a critical exam and interview skill, but in real production environments, engineers use scripts and tools to avoid human error at scale:

import ipaddress

def subnet_info(network_str):
    network = ipaddress.ip_network(network_str, strict=False)
    hosts = list(network.hosts())
    print(f"Network:          {network.network_address}")
    print(f"Broadcast:        {network.broadcast_address}")
    print(f"Prefix Length:    /{network.prefixlen}")
    print(f"Total Addresses:  {network.num_addresses}")
    print(f"Usable Hosts:     {len(hosts)}")
    print(f"First Usable:     {hosts[0] if hosts else 'N/A'}")
    print(f"Last Usable:      {hosts[-1] if hosts else 'N/A'}")

subnet_info("192.168.1.64/27")

Output:

Network:          192.168.1.64
Broadcast:        192.168.1.95
Prefix Length:    /27
Total Addresses:  32
Usable Hosts:     30
First Usable:     192.168.1.65
Last Usable:      192.168.1.94

You can also use Python to automatically design a VLSM plan given a list of host requirements:

import ipaddress

def vlsm_plan(base_network, host_requirements):
    base = ipaddress.ip_network(base_network)
    # Sort largest requirement first - standard VLSM best practice
    sorted_reqs = sorted(host_requirements, key=lambda x: x[1], reverse=True)
    available = [base]
    plan = []

    for name, hosts_needed in sorted_reqs:
        needed_prefix = 32
        while (2 ** (32 - needed_prefix) - 2) < hosts_needed:
            needed_prefix -= 1

        for i, net in enumerate(available):
            if net.prefixlen <= needed_prefix:
                subnets = list(net.subnets(new_prefix=needed_prefix))
                assigned = subnets[0]
                remaining = subnets[1:]
                available.pop(i)
                available.extend(remaining)
                plan.append((name, assigned))
                break

    return plan

requirements = [("Sales", 50), ("Engineering", 20), ("P2P-Link", 2)]
for name, subnet in vlsm_plan("192.168.1.0/24", requirements):
    print(f"{name:12} -> {subnet}")

Output:

Sales        -> 192.168.1.0/26
Engineering  -> 192.168.1.64/27
P2P-Link     -> 192.168.1.96/30

Comparison Table: Common Prefix Lengths at a Glance

CIDRSubnet MaskTotal AddressesUsable HostsTypical Use
/24255.255.255.0256254Standard LAN segment
/25255.255.255.128128126Medium LAN segment
/26255.255.255.1926462Small department/VLAN
/27255.255.255.2243230Small office/branch
/28255.255.255.2401614Small equipment subnet
/29255.255.255.24886Very small subnet (e.g., DMZ segment)
/30255.255.255.25242Point-to-point router links
/32255.255.255.25511 (host route)Loopback interfaces, host-specific routes

Best Practices

  1. Always use VLSM in real deployments rather than fixed-size subnetting — it dramatically reduces wasted address space, especially valuable in constrained private address plans.
  2. Reserve /30 (or /31 where supported) for point-to-point links — there’s no reason to waste a full /26 or larger subnet on a link that only ever needs two addresses.
  3. Plan for growth — don’t size a subnet exactly to today’s host count; leave reasonable headroom for expected growth to avoid painful re-addressing later.
  4. Document your subnet plan centrally (spreadsheet or IPAM tool) — including purpose, VLAN ID, and assigned prefix — so the whole team has a single source of truth.
  5. Use automation/scripts to validate subnetting math on large designs — manual errors are common and can be costly to discover after deployment.

Troubleshooting Subnetting Issues

Symptom: Two Devices on the “Same Subnet” Can’t Communicate

Check: Do they actually have the same subnet mask configured? A common, subtle mistake is one device configured with /24 and another with /25 — even if their IP addresses look like they’re in the same range, differing masks mean they calculate different network/broadcast boundaries and may not correctly recognize each other as local.

Symptom: Device Can’t Reach Anything, Not Even the Default Gateway

Check: Is the default gateway’s IP address actually within the same subnet as the device? A gateway address outside the configured subnet range is a very common misconfiguration.

Symptom: Broadcast Traffic Behaving Unexpectedly

Check: Confirm the calculated broadcast address for the subnet — a common error is assigning what should be the broadcast address (all host bits = 1) to an actual device, causing broadcast traffic issues on that segment.

Summary

IPv4 subnetting is fundamentally simple arithmetic once you internalize the core formulas: total addresses = 2^(32−prefix), usable hosts = that number minus 2, and subnets from borrowed bits = 2^n. VLSM extends this by allowing differently sized subnets tailored precisely to each segment’s actual needs, dramatically improving address space efficiency. Whether you calculate by hand, verify with Cisco’s show ip interface commands, or automate with Python, the underlying math never changes — master it once, and it will serve you for your entire networking career.

Further Reading

Total
2
Shares

Leave a Reply

Previous Post
Explain the role and function of network components

Explain the Role and Function of Network Components

Next Post
Describe the need for private IPv4 addressing

Describe the Need for Private IPv4 Addressing

Related Posts