Skip to main content
All tracks
Computer Networks

IP Addressing, Subnetting and Routing

IPv4 addresses​

An IPv4 address is 32 bits, written as four octets (192.168.10.25). It has a network part and a host part, separated by the subnet mask or CIDR prefix.

ClassFirst octetDefault maskPrivate range
A1 to 126/810.0.0.0 to 10.255.255.255
B128 to 191/16172.16.0.0 to 172.31.255.255
C192 to 223/24192.168.0.0 to 192.168.255.255

Classless addressing (CIDR) uses an explicit prefix length such as 192.168.10.0/26.

Subnetting example​

192.168.10.0/26

Prefix 26 -> mask 255.255.255.192
Host bits = 32 - 26 = 6 -> 2^6 = 64 addresses
Usable hosts = 64 - 2 = 62 (network + broadcast excluded)
Network: 192.168.10.0
Broadcast: 192.168.10.63
Range: 192.168.10.1 to 192.168.10.62
import ipaddress

net = ipaddress.ip_network("192.168.10.0/26")
print(net.netmask, net.broadcast_address, net.num_addresses - 2)
# 255.255.255.192 192.168.10.63 62

NAT​

Network Address Translation lets many private hosts share one public IP by rewriting addresses and ports at the router. It conserves IPv4 addresses but breaks true end-to-end connectivity.

IPv6​

128-bit addresses (2001:db8::1), no broadcast, built-in auto-configuration, and no NAT needed because the address space is huge.

Routing​

A router looks up the destination in its routing table using longest-prefix match and forwards to the next hop.

ApproachAlgorithms / protocols
Distance vectorBellman-Ford; RIP
Link stateDijkstra; OSPF
Path vectorBGP (between autonomous systems)

ICMP​

Control messages for the IP layer: ping (echo request/reply), traceroute (TTL expired), destination unreachable.

ping -c 4 example.com
traceroute example.com

The TTL field is decremented at every hop and the packet is dropped at zero, which stops routing loops.

Finished reading?

Mark it complete to track your progress across the docs.

Questions and discussion

Stuck on something here, or found a clearer way to explain it? Start a thread.

All discussions
  • Ask a question or share what helped
  • React to useful answers
  • Sign in with GitHub to post

Comments are stored in GitHub Discussions and shown here by giscus. PrepVerse never sees your GitHub password.