Post

IPv4 Addressing Explained

Every device that communicates over a network needs an address — a unique identifier that tells the network where to deliver traffic. IPv4 (Internet Protocol version 4) has been that addressing system since 1981, and despite the gradual adoption of IPv6, the vast majority of networks you will manage as a Linux administrator still rely on IPv4 every day.

Understanding IPv4 is not just theory. It directly affects how you configure network interfaces, write firewall rules, design subnets, and troubleshoot connectivity issues.

What is an IP Address?

An IPv4 address is a 32-bit number that uniquely identifies a device (called a host) on a network. It is written in dotted-decimal notation — four decimal numbers separated by dots, each representing 8 bits (one octet):

1
192.168.1.100

Each of the four octets ranges from 0 to 255, because 8 binary bits can represent at most 2⁸ = 256 values (0–255).


Binary and Decimal: The Foundation

Computers work in binary (base 2). Every IP address is ultimately a sequence of 32 ones and zeros. Converting between binary and decimal is a core skill for subnetting.

Bit Position Values

Each bit in an octet has a positional value, doubling from right to left:

Bit Position 7 6 5 4 3 2 1 0
Value 128 64 32 16 8 4 2 1

To convert binary → decimal: add up the values of every position that has a 1.

1
2
3
4
11000000  =  128 + 64  =  192
10101000  =  128 + 32 + 8  =  168
00000001  =  1
01100100  =  64 + 32 + 4  =  100

So 192.168.1.100 in full binary is:

1
2
11000000 . 10101000 . 00000001 . 01100100
   192   .    168   .    1     .   100

To convert decimal → binary: repeatedly subtract the largest power of 2 that fits.

1
2
3
4
5
6
Convert 172:
172 - 128 = 44  → bit 7 = 1
 44 -  32 = 12  → bit 5 = 1
 12 -   8 =  4  → bit 3 = 1
  4 -   4 =  0  → bit 2 = 1
Result: 10101100

Tip: Practise converting a few octets by hand. Once you can do it quickly, subnetting calculations become straightforward.


Address Structure: Network and Host Portions

An IPv4 address has two logical parts:

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

Which bits belong to the network and which to the host is determined by the subnet mask.

1
2
3
4
5
IP Address:   192.168.1.100
Subnet Mask:  255.255.255.0

Network:      192.168.1.0    (first 24 bits)
Host:         .100           (last 8 bits)

The subnet mask is all 1s in the network portion and all 0s in the host portion:

1
255.255.255.0  =  11111111.11111111.11111111.00000000

A bitwise AND of the IP address and the subnet mask always gives you the network address:

1
2
3
  11000000.10101000.00000001.01100100   (192.168.1.100)
& 11111111.11111111.11111111.00000000   (255.255.255.0)
= 11000000.10101000.00000001.00000000   (192.168.1.0)

Address Classes

Before CIDR (classless inter-domain routing) became standard, the IPv4 address space was divided into fixed classes based on the value of the first octet. You will still encounter class terminology in documentation, hardware, and exams.

Class First Octet Range Default Mask Network Bits Host Bits Networks Hosts per Network
A 1 – 126 255.0.0.0 /8 8 24 126 16,777,214
B 128 – 191 255.255.0.0 /16 16 16 16,384 65,534
C 192 – 223 255.255.255.0 /24 24 8 2,097,152 254
D 224 – 239 Multicast
E 240 – 255 Reserved/Experimental

Note: 127.x.x.x is reserved for loopback and does not belong to Class A usable space. 127.0.0.1 always refers to the local machine itself.

Why two fewer hosts? Every subnet reserves two addresses: the network address (all host bits = 0) and the broadcast address (all host bits = 1). Neither can be assigned to a device.

1
2
3
4
Network:    192.168.1.0    → all host bits 0
First host: 192.168.1.1
Last host:  192.168.1.254
Broadcast:  192.168.1.255  → all host bits 1

CIDR Notation (Classless Inter-Domain Routing)

CIDR replaced classful addressing in 1993. Instead of fixed class boundaries, the prefix length — written as a / followed by the number of network bits — defines the split between network and host portions.

1
2
3
4
192.168.1.0/24   →  24 network bits, 8 host bits
10.0.0.0/8       →  8 network bits, 24 host bits
172.16.0.0/12    →  12 network bits, 20 host bits
192.168.10.0/26  →  26 network bits, 6 host bits

Calculating Subnet Size

Given a prefix length /n:

  • Number of host addresses = 2^(32−n)
  • Usable hosts = 2^(32−n) − 2 (subtract network and broadcast addresses)
CIDR Subnet Mask Total Addresses Usable Hosts
/8 255.0.0.0 16,777,216 16,777,214
/16 255.255.0.0 65,536 65,534
/24 255.255.255.0 256 254
/25 255.255.255.128 128 126
/26 255.255.255.192 64 62
/27 255.255.255.224 32 30
/28 255.255.255.240 16 14
/29 255.255.255.248 8 6
/30 255.255.255.252 4 2
/31 255.255.255.254 2 0*
/32 255.255.255.255 1 1 (host route)

/30 is the smallest subnet used for point-to-point links between two routers — exactly two usable host addresses. /31 is also valid for point-to-point links per RFC 3021.


Subnetting: Dividing a Network

Subnetting splits a large network into smaller, more manageable segments. This improves security (traffic stays within segments), reduces broadcast domains, and makes IP address allocation more efficient.

Worked Example: Subnet a /24

You have been assigned 192.168.10.0/24 and need 4 equal subnets.

Step 1 — How many bits do you need to borrow from the host portion?
2^n ≥ 4 → n = 2 bits borrowed → new prefix = /24 + 2 = /26

Step 2 — Calculate the block size:
2^(32 − 26) = 64 addresses per subnet

Step 3 — List the four subnets:

Subnet Network Address Usable Range Broadcast Hosts
1 192.168.10.0/26 .1 – .62 .63 62
2 192.168.10.64/26 .65 – .126 .127 62
3 192.168.10.128/26 .129 – .190 .191 62
4 192.168.10.192/26 .193 – .254 .255 62

Each subnet starts at a multiple of the block size (0, 64, 128, 192).

Worked Example: How Many Subnets Fit?

You have 10.0.0.0/8 and want subnets of /20. How many fit?

Bits borrowed = 20 − 8 = 12 → 2^12 = 4,096 subnets, each with 2^(32−20) − 2 = 4,094 usable hosts.


Public vs Private Addresses

Not all IPv4 addresses route on the public internet. Three ranges are reserved for private use (RFC 1918) and are never routed between autonomous systems:

Range CIDR Class Common Use
10.0.0.010.255.255.255 10.0.0.0/8 A Large enterprise, cloud VPCs
172.16.0.0172.31.255.255 172.16.0.0/12 B Medium networks, Docker default
192.168.0.0192.168.255.255 192.168.0.0/16 C Home, small office, labs

Devices using private addresses access the internet through NAT (Network Address Translation) — a router maps many private addresses to one or a few public addresses.


Special and Reserved Addresses

Address / Range Purpose
0.0.0.0/8 “This network” — used before an address is assigned; also means “all interfaces” in server bind contexts
127.0.0.0/8 Loopback127.0.0.1 always refers to the local machine
169.254.0.0/16 APIPA (Link-local) — auto-assigned when DHCP fails; not routable
224.0.0.0/4 Multicast — send once to multiple subscribers
255.255.255.255 Limited broadcast — delivers to all hosts on the local segment
192.0.2.0/24 TEST-NET-1 — documentation and examples (RFC 5737)
198.51.100.0/24 TEST-NET-2 — documentation and examples
203.0.113.0/24 TEST-NET-3 — documentation and examples

Tip: When writing documentation or blog posts, always use 192.0.2.x, 198.51.100.x, or 203.0.113.x for example addresses. They are guaranteed never to be assigned to real hosts, so there is no risk of accidentally publishing someone’s actual address.


Configuring IPv4 on Linux

View Current Addresses

1
2
3
ip addr show              # All interfaces
ip addr show eth0         # Specific interface
ip -4 addr show           # IPv4 only

Assign a Static IP (Temporary — Lost on Reboot)

1
2
3
sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip link set eth0 up
sudo ip route add default via 192.168.1.1

View the Routing Table

1
2
3
ip route show
# default via 192.168.1.1 dev eth0
# 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100

Persistent Configuration (Netplan — Ubuntu 18.04+)

1
2
3
4
5
6
7
8
9
10
11
12
# /etc/netplan/01-netcfg.yaml
network:
  version: 2
  ethernets:
    eth0:
      addresses:
        - 192.168.1.100/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]
1
sudo netplan apply

Persistent Configuration (nmcli — RHEL/CentOS)

1
2
3
4
5
sudo nmcli con mod eth0 ipv4.addresses 192.168.1.100/24
sudo nmcli con mod eth0 ipv4.gateway 192.168.1.1
sudo nmcli con mod eth0 ipv4.dns "8.8.8.8 1.1.1.1"
sudo nmcli con mod eth0 ipv4.method manual
sudo nmcli con up eth0

Useful Diagnostic Commands

1
2
3
4
5
6
ping 192.168.1.1               # Test reachability
ping -c 4 8.8.8.8              # Ping with 4 packets
traceroute 8.8.8.8             # Trace the route to a host
ss -tlnp                       # Show listening TCP ports
ip neigh show                  # ARP table (MAC to IP mappings)
nmap -sn 192.168.1.0/24        # Discover live hosts on a subnet

IPv4 Exhaustion and IPv6

The total IPv4 address space is 2^32 = 4,294,967,296 addresses — about 4.3 billion. IANA allocated the last blocks to regional registries in 2011. Private addressing and NAT have extended IPv4’s life, but the long-term solution is IPv6, which uses 128-bit addresses (2^128 ≈ 3.4 × 10^38 addresses — effectively inexhaustible).

Most modern Linux systems and cloud providers support dual-stack operation — running IPv4 and IPv6 simultaneously — so you will encounter both protocols. IPv4 knowledge remains essential for the foreseeable future.


Quick Reference

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
IPv4 address:   32 bits, written as 4 octets (0–255) separated by dots
Subnet mask:    defines the network/host boundary
CIDR notation:  /n where n = number of network bits
Network addr:   IP AND mask (all host bits = 0)
Broadcast addr: all host bits = 1
Usable hosts:   2^(32−n) − 2

Private ranges:
  10.0.0.0/8        Class A private
  172.16.0.0/12     Class B private
  192.168.0.0/16    Class C private

Special:
  127.0.0.1         Loopback
  169.254.x.x       Link-local (APIPA)
  255.255.255.255   Broadcast

Linux commands:
  ip addr show      View IP addresses
  ip route show     View routing table
  ip neigh show     View ARP table
  ping / traceroute Test connectivity

Conclusion

IPv4 addressing is the language networks use to find and deliver data to the right destination. Every concept covered here — octets, binary conversion, subnet masks, CIDR notation, subnetting, and the public/private distinction — feeds directly into practical sysadmin work: configuring interfaces, writing firewall rules, designing network topologies, and troubleshooting why a packet is not arriving where it should.

The most important skill to develop is the ability to look at a CIDR block like 10.10.4.0/22 and immediately know its network address, broadcast address, usable host range, and number of available hosts. That fluency comes with practice, and the commands in the Linux configuration section give you a real environment to experiment in.

Additional Resources


This post is licensed under CC BY 4.0 by the author.