Skip to content

Ip_addressing


An IPv4 address is a 32-bit number divided into 4 octets (8 bits each).

IPv4 Address Structure
+------------------------------------------------------------------+
Example: 192.168.1.100
+------------------------------------------------------------------+
| |
| Binary: 11000000 . 10101000 . 00000001 . 01100100 |
| | | | | |
| Octet 1 Octet 2 Octet 3 Octet 4 |
| 192 168 1 100 |
| |
| Total bits: 32 bits |
| Total possible addresses: 2^32 = 4,294,967,296 |
| |
+------------------------------------------------------------------+
IPv4 Dotted Decimal:
+------------------------------------------------------------------+
| |
| Each octet: 0-255 (8 bits = 256 values) |
| |
| Range: 0.0.0.0 to 255.255.255.255 |
| |
+------------------------------------------------------------------+

IPv4 Address Classes
+------------------------------------------------------------------+
Class | First Octet Range | Default Subnet Mask | Networks | Hosts/Network
------|---------------------|--------------------|----------|--------------
A | 1 - 126 | 255.0.0.0 (/8) | 126 | 16,777,214
B | 128 - 191 | 255.255.0.0 (/16) | 16,384 | 65,534
C | 192 - 223 | 255.255.255.0 (/24)|2,097,152| 254
D | 224 - 239 | None (Multicast) | - | -
E | 240 - 255 | None (Reserved) | - | -
+------------------------------------------------------------------+
Special Addresses:
+------------------------------------------------------------------+
| 0.0.0.0 | This network (RFC 1122) |
| 127.0.0.1 | Loopback address |
| 255.255.255.255 | Limited broadcast |
| x.x.x.0 | Network address (all host bits = 0) |
| x.x.x.255 | Broadcast address (all host bits = 1) |
+------------------------------------------------------------------+

These addresses are not routable on the Internet and are used internally.

Private IP Ranges
+------------------------------------------------------------------+
Class | Network Address | Range | CIDR
------|-----------------------|----------------------------|---------
A | 10.0.0.0 | 10.0.0.0 - 10.255.255.255 | /8
B | 172.16.0.0 | 172.16.0.0 - 172.31.255.255|/12
C | 192.168.0.0 | 192.168.0.0 - 192.168.255.255|/16
+------------------------------------------------------------------+
Why Private Addresses?
+------------------------------------------------------------------+
| - IPv4 address exhaustion |
| - Security (not directly accessible from internet) |
| - Reuse in different networks |
| - Requires NAT to access internet |
+------------------------------------------------------------------+
Example Network Topology:
+------------------------------------------------------------------+
Internet
|
|
[Router/NAT]
|
+-------------+-------------+
| | |
LAN 1 LAN 2 LAN 3
10.0.1.x 10.0.2.x 10.0.3.x
Private Private Private
+------------------------------------------------------------------+

A subnet mask determines which portion of an IP address is the network and which is the host.

Subnet Mask
+------------------------------------------------------------------+
Example: 192.168.1.100/24
+------------------------------------------------------------------+
| |
| IP Address (binary): |
| 11000000 . 10101000 . 00000001 . 01100100 |
| |
| Subnet Mask (binary): |
| 11111111 . 11111111 . 11111111 . 00000000 |
| |
| Subnet Mask (decimal): |
| 255 . 255 . 255 . 0 |
| |
| /24 = 24 ones in the network portion |
| |
+------------------------------------------------------------------+
Common Subnet Masks:
+------------------------------------------------------------------+
CIDR | Dotted Decimal | Total IPs | Usable IPs | Powers of 2
------|--------------------|------------|------------|-------------
/32 | 255.255.255.255 | 1 | 0 | -
/31 | 255.255.255.254 | 2 | 0* | 2
/30 | 255.255.255.252 | 4 | 2 | 4
/29 | 255.255.255.248 | 8 | 6 | 8
/28 | 255.255.255.240 | 16 | 14 | 16
/27 | 255.255.255.224 | 32 | 30 | 32
/26 | 255.255.255.192 | 64 | 62 | 64
/25 | 255.255.255.128 | 128 | 126 | 128
/24 | 255.255.255.0 | 256 | 254 | 256
/23 | 255.255.254.0 | 512 | 510 | 512
/22 | 255.255.252.0 | 1,024 | 1,022 | 1,024
/21 | 255.255.248.0 | 2,048 | 2,046 | 2,048
/20 | 255.255.240.0 | 4,096 | 4,094 | 4,096
* /31 is for point-to-point links (RFC 3021)
* Always subtract 2 for network and broadcast addresses
+------------------------------------------------------------------+

IPv6 uses 128 bits (16 bytes) instead of 32 bits.

IPv6 Address Structure
+------------------------------------------------------------------+
Example: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
+------------------------------------------------------------------+
| |
| Full form: |
| 2001:0db8:85a3:0000:0000:8a2e:0370:7334 |
| |
| 8 groups of 16 bits each = 128 bits total |
| |
+------------------------------------------------------------------+
IPv6 Address Types:
+------------------------------------------------------------------+
| |
| Unicast | Single interface address |
| +---------|--------------------------------------------------|
| | Global Unicast | Public address (2000::/3) |
| | Link-Local | FE80::/10 (auto-configured) |
| | Unique Local | FC00::/7 (private) |
| | Loopback | ::1 |
| +---------|--------------------------------------------------|
| |
| Multicast | FF00::/8 (one-to-many) |
| |
| Anycast | One-to-nearest (from the group) |
| |
+------------------------------------------------------------------+
IPv6 Address Notation Shortcuts:
+------------------------------------------------------------------+
Rule 1: Leading zeros in each hextet can be removed
2001:0db8:85a3:0000:0000:8a2e:0370:7334
2001: db8:85a3: 0: 0: 8a2e: 370:7334
Rule 2: One consecutive group of zeros can be replaced with ::
2001:db8:85a3::8a2e:0370:7334
Invalid: 2001::85a3::7334 (ambiguous!)
+------------------------------------------------------------------+
IPv6 Prefix Lengths:
+------------------------------------------------------------------+
/64 | Subnet (typical for LAN)
/48 | Site prefix
/32 | Regional registry prefix
/128 | Single interface
+------------------------------------------------------------------+

Special IPv6 Addresses
+------------------------------------------------------------------+
Address | Full Form | Description
----------------------|--------------------------------|------------------
:: (unspecified) | 0000:0000:0000:0000: | No address
| 0000:0000:0000:0000 |
----------------------|--------------------------------|------------------
::1 (loopback) | 0000:0000:0000:0000: | Localhost
| 0000:0000:0000:0001 |
----------------------|--------------------------------|------------------
2001:db8::/32 | Documentation prefix | Not routable
----------------------|--------------------------------|------------------
fe80::/10 | Link-Local | Auto-configured
----------------------|--------------------------------|------------------
fc00::/7 | Unique Local Address | Private
----------------------|--------------------------------|------------------
ff00::/8 | Multicast | Multi-way
----------------------|--------------------------------|------------------
+------------------------------------------------------------------+
IPv6 Link-Local Address:
+------------------------------------------------------------------+
Automatically generated from MAC address (EUI-64):
MAC: 00:1a:2b:3c:4d:5e
|
| Insert FF:FE in middle
v
EUI-64: 001a:2bff:fe3c:4d5e
|
| Toggle 7th bit
v
Modified: 021a:2bff:fe3c:4d5e
|
| Add prefix
v
fe80::21a:2bff:fe3c:4d5e
+------------------------------------------------------------------+

IPv4 vs IPv6 Comparison
+------------------------------------------------------------------+
Feature | IPv4 | IPv6
---------------------|-------------------|-------------------
Address Length | 32 bits | 128 bits
Address Space | ~4.3 billion | ~340 undecillion
Notation | Dotted decimal | Hex groups
Subnet Mask | Required | Prefix length
ARP | Used | NDP (Neighbor Discovery)
Fragmentation | Router and host | Host only
Header Size | 20-60 bytes | 40 bytes (fixed)
Security | Optional (IPsec)| Built-in IPsec
Configuration | Manual or DHCP | Auto-config (SLAAC)
NAT | Required | Not needed
Broadcast | Yes | No (multicast)
Quality of Service | DSCP field | Traffic class field
+------------------------------------------------------------------+
IPv4 Exhaustion Timeline:
+------------------------------------------------------------------+
1981 - IPv4 developed
1983 - ARPANET converts to TCP/IP
1992 -ripe.net established (regional registries)
2011 - IANA exhaustion (last /8 blocks allocated)
2012 - RIPE NCC exhaustion
2015 - ARIN exhaustion (North America)
2019 - RIPE NCC runs out of free pools
2020+ - Increasing NAT usage, IPv6 adoption
+------------------------------------------------------------------+

Terminal window
# Modern command (ip)
ip addr show
ip addr show eth0
# Show only IPv4 addresses
ip -4 addr show
# Show only IPv6 addresses
ip -6 addr show
# Legacy command (ifconfig)
ifconfig
ifconfig eth0
# Check specific interface
ip link show
ip link set eth0 up
ip link set eth0 down
Terminal window
# View routing table
ip route show
ip route
# Legacy
route -n
netstat -rn
# IPv6 routes
ip -6 route show
# Get route to specific destination
ip route get 8.8.8.8
Terminal window
# View ARP cache
ip neigh show
arp -a
# Add static ARP entry
ip neigh add 192.168.1.1 lladdr aa:bb:cc:dd:ee:ff dev eth0
# Delete ARP entry
ip neigh del 192.168.1.1 dev eth0

In this chapter, you learned:

  • ✅ IPv4 address structure (32-bit, 4 octets)
  • ✅ IPv4 address classes (A, B, C, D, E)
  • ✅ Private IP addresses (RFC 1918)
  • ✅ Subnet masks and CIDR notation
  • ✅ IPv6 address structure (128-bit)
  • ✅ IPv6 address types and special addresses
  • ✅ IPv4 vs IPv6 comparison
  • ✅ Linux network commands

Chapter 4: Subnetting Fundamentals


Last Updated: February 2026