IP Addresses, Subnets, and Routing
IPv4 and IPv6
Every device on the internet has an IP address. IPv4 uses 32-bit addresses, written as four numbers separated by dots (e.g., 192.168.1.1). This gives about 4.3 billion addresses — enough for the early internet, but not enough today.
IPv6 uses 128-bit addresses, written as eight groups of hexadecimal digits separated by colons (e.g., 2001:db8::1). The double-colon :: is shorthand for consecutive zero groups, so 2001:0db8:0000:0000:0000:0000:0000:0001 becomes 2001:db8::1.
Subnets and CIDR Notation
A single IP network can be divided into smaller subnets. CIDR (Classless Inter-Domain Routing) notation expresses both the network and the subnet size: 192.168.1.0/24 means the network 192.168.1.0 with a 24-bit network prefix, leaving 8 bits for host addresses — that is, 256 possible addresses (254 usable, since the first is the network and the last is the broadcast).
| Notation | Network bits | Host bits | Addresses |
|---|---|---|---|
| /24 | 24 | 8 | 256 |
| /25 | 25 | 7 | 128 |
| /26 | 26 | 6 | 64 |
| /16 | 16 | 16 | 65,536 |
Subnets let you divide a large network into smaller ones — e.g., one subnet per floor in an office building — reducing broadcast traffic and improving security.
How Routers Forward Packets
When a device wants to send a packet to another device, it checks whether the destination is on the same subnet. If so, it sends the packet directly (using the destination's MAC address via ARP).
If the destination is on a different subnet, the device sends the packet to its default gateway — a router. The router consults its routing table: a list of (destination network, next hop) pairs. It finds the entry that matches the destination IP and forwards the packet to the next hop. This process repeats at every router along the path.
On the internet, BGP (Border Gateway Protocol) is the routing protocol that connects autonomous systems (networks operated by different organizations). Each autonomous system announces which IP ranges it can reach, and BGP routers exchange these announcements to build a global routing table.
Private vs. Public Addresses
Some IP ranges are private (not routable on the internet) — used inside home and office networks:
| Range | CIDR |
|---|---|
| 10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 |
| 172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 |
| 192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 |
A NAT (Network Address Translation) router maps private addresses to a single public IP, allowing many devices to share one public address.
Next Steps
Learn about ports and sockets · See how DNS resolves names to addresses