An IPv4 address is a 32-bit number written in dotted decimal notation - four octets (8-bit groups) separated by dots. Each octet ranges from 0 to 255.
Example: 192.168.1.100 = 11000000.10101000.00000001.01100100 in binary
| Class | First Octet Range | Default Subnet Mask | Networks | Hosts/Network | Use |
|---|---|---|---|---|---|
| A | 1 - 126 | 255.0.0.0 (/8) | 126 | 16,777,214 | Large organizations |
| B | 128 - 191 | 255.255.0.0 (/16) | 16,384 | 65,534 | Medium organizations |
| C | 192 - 223 | 255.255.255.0 (/24) | 2,097,152 | 254 | Small organizations |
| D | 224 - 239 | N/A | N/A | N/A | Multicast |
| E | 240 - 255 | N/A | N/A | N/A | Reserved/Experimental |
| Address/Range | Purpose |
|---|---|
| 127.0.0.0 - 127.255.255.255 | Loopback (localhost) - 127.0.0.1 is most common |
| 10.0.0.0 - 10.255.255.255 | Private Class A (RFC 1918) |
| 172.16.0.0 - 172.31.255.255 | Private Class B (RFC 1918) |
| 192.168.0.0 - 192.168.255.255 | Private Class C (RFC 1918) |
| 169.254.0.0 - 169.254.255.255 | APIPA (Automatic Private IP Addressing) - when DHCP fails |
| 0.0.0.0 | Default route / unspecified address |
| 255.255.255.255 | Limited broadcast (all hosts on local network) |
IPv6 uses 128-bit addresses written as 8 groups of 4 hexadecimal digits separated by colons.
Example: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Abbreviation rules:
| Feature | IPv4 | IPv6 |
|---|---|---|
| Address Size | 32 bits | 128 bits |
| Address Format | Dotted decimal (192.168.1.1) | Hexadecimal colon notation |
| Total Addresses | ~4.3 billion | ~340 undecillion |
| Header Size | 20-60 bytes (variable) | 40 bytes (fixed) |
| NAT Required | Yes (address exhaustion) | No (enough addresses) |
| Security | Optional (IPSec) | Built-in (IPsec mandatory) |
| Broadcast | Yes | No (uses multicast/anycast) |
| Auto-configuration | DHCP | SLAAC (Stateless Address Autoconfiguration) |
| Type | Prefix | Purpose | Example |
|---|---|---|---|
| Global Unicast | 2000::/3 | Routable Internet addresses | 2001:db8::1 |
| Link-Local | fe80::/10 | Communication on same link | fe80::1 |
| Unique Local | fc00::/7 | Private addressing (like RFC 1918) | fc00::1 |
| Multicast | ff00::/8 | One-to-many communication | ff02::1 |
| Loopback | ::1 | Local host (like 127.0.0.1) | ::1 |
| Unspecified | :: | Default route (like 0.0.0.0) | :: |
Subnet masks divide IP addresses into network and host portions. CIDR (Classless Inter-Domain Routing) replaces class-based addressing with flexible subnetting.
| CIDR | Subnet Mask | Network Bits | Host Bits | Total Hosts | Usable Hosts |
|---|---|---|---|---|---|
| /8 | 255.0.0.0 | 8 | 24 | 16,777,216 | 16,777,214 |
| /16 | 255.255.0.0 | 16 | 16 | 65,536 | 65,534 |
| /24 | 255.255.255.0 | 24 | 8 | 256 | 254 |
| /25 | 255.255.255.128 | 25 | 7 | 128 | 126 |
| /26 | 255.255.255.192 | 26 | 6 | 64 | 62 |
| /27 | 255.255.255.224 | 27 | 5 | 32 | 30 |
| /28 | 255.255.255.240 | 28 | 4 | 16 | 14 |
| /29 | 255.255.255.248 | 29 | 3 | 8 | 6 |
| /30 | 255.255.255.252 | 30 | 2 | 4 | 2 |
| /31 | 255.255.255.254 | 31 | 1 | 2 | 0 |
| /32 | 255.255.255.255 | 32 | 0 | 1 | 1 |
DHCP automatically assigns IP addresses to devices on a network. The DHCP process involves four steps:
| Method | Advantages | Disadvantages | Use Cases |
|---|---|---|---|
| Static IP | Consistent address, no DHCP dependency, easy to remember | Manual configuration, potential conflicts, less flexible | Servers, printers, routers, infrastructure devices |
| Dynamic IP | Automatic configuration, no conflicts, efficient address usage | Address changes, requires DHCP server, less predictable | Client computers, mobile devices, temporary connections |
NAT allows multiple devices to share a single public IP address by translating private addresses to public ones. It was developed to address IPv4 address exhaustion.
| Benefits | Limitations |
|---|---|
| Conserves IPv4 addresses | Breaks end-to-end connectivity |
| Provides basic security (hides internal network) | Problems with peer-to-peer applications |
| Allows network renumbering | Complicates VoIP and video conferencing |
| Reduces need for public addresses | Performance overhead |
SLAAC allows devices to automatically configure their own IPv6 addresses without a central server:
| Command | Purpose | Example Usage |
|---|---|---|
| ipconfig / ifconfig | Show IP configuration | ipconfig /all (Windows) |
| ping | Test connectivity | ping 8.8.8.8 |
| tracert / traceroute | Trace network path | tracert google.com |
| nslookup | DNS resolution test | nslookup google.com |
| arp -a | Show ARP table | arp -a |
| netstat -rn | Show routing table | netstat -rn |
Client device
-> local network interface
-> default gateway or switch
-> routing/security decision
-> destination service
For IP, explain each hop by naming the address, protocol, port, and decision made at that layer.
from ipaddress import ip_interface
first = ip_interface('192.0.2.14/27')
second = ip_interface('192.0.2.30/27')
third = ip_interface('192.0.2.40/27')
print(first.network)
print(first.network == second.network)
print(first.network == third.network)
192.0.2.0/27
True
False
The host applies its subnet prefix to its own address and the destination. If the destination is on-link, it resolves the local hardware address and sends directly.
Outbound NAT records a mapping from private source addresses and ports to a public address. Return traffic can follow that existing state.
Both devices answer for the same address, so neighbor caches can alternate between their hardware addresses. Connections may reach one device and then the other, producing unstable access rather than a clean failure.
Explore 500+ free tutorials across 20+ languages and frameworks.