Computer Networking Cheatsheet
IP Addressing
Use this Computer Networking reference while you build software engineering projects, review code, or refresh the syntax you reach for most.
Anatomy of an IPv4 address
32 bits written as four dotted decimal octets, each 0-255. A mask splits it into a network part and a host part.
192 . 168 . 10 . 37 11000000.10101000.00001010.00100101 address 192.168.10.37 11111111.11111111.11111111.00000000 mask 255.255.255.0 (/24) 11000000.10101000.00001010.00000000 network 192.168.10.0 11000000.10101000.00001010.11111111 broadcast 192.168.10.255
Rules that always hold in IPv4: the all-zeros host is the network address, the all-ones host is the broadcast address, and neither is assignable. A /24 therefore has 256 addresses but only 254 usable hosts.
Legacy classes
Classful addressing is obsolete (CIDR replaced it in 1993) but the vocabulary survives in exams, docs, and tool defaults.
| Class | First octet | Default mask | Networks | Hosts per network |
|---|---|---|---|---|
| A | 1-126 | /8 255.0.0.0 | 126 | 16,777,214 |
| B | 128-191 | /16 255.255.0.0 | 16,384 | 65,534 |
| C | 192-223 | /24 255.255.255.0 | 2,097,152 | 254 |
| D | 224-239 | none (multicast) | — | — |
| E | 240-255 | none (reserved) | — | — |
127.0.0.0/8 is carved out of class A for loopback, which is why class A stops
at 126.
Private ranges (RFC 1918) and other reserved blocks
Private addresses are not routable on the public internet, so they must be translated by NAT to reach it.
| Block | CIDR | Addresses | Notes |
|---|---|---|---|
| 10.0.0.0-10.255.255.255 | 10.0.0.0/8 | 16,777,216 | RFC 1918, big flat enterprise space |
| 172.16.0.0-172.31.255.255 | 172.16.0.0/12 | 1,048,576 | RFC 1918, Docker default neighborhood |
| 192.168.0.0-192.168.255.255 | 192.168.0.0/16 | 65,536 | RFC 1918, home routers |
| 127.0.0.0/8 | loopback | 16,777,216 | 127.0.0.1 localhost |
| 169.254.0.0/16 | link-local | 65,536 | APIPA, DHCP failed · cloud metadata 169.254.169.254 |
| 100.64.0.0/10 | CGNAT | 4,194,304 | RFC 6598, carrier-grade NAT, Tailscale |
| 0.0.0.0/8 | this network | — | 0.0.0.0 means "any" when binding |
| 224.0.0.0/4 | multicast | — | groups, not hosts |
| 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 | documentation | 768 | RFC 5737, safe in examples |
A common interview trap: 172.32.0.0 is public, because the private range
stops at 172.31.255.255.
Static, DHCP, and link-local assignment
ip addr show # every address, all interfaces ip -4 addr show dev eth0 # just IPv4 on one NIC ip addr add 192.168.10.37/24 dev eth0 # static, runtime only ip addr del 192.168.10.37/24 dev eth0 ip route add default via 192.168.10.1 # gateway dhclient -v eth0 # request a lease
Persistent config depends on the distro: /etc/netplan/*.yaml (Ubuntu),
nmcli con mod (NetworkManager, RHEL and Fedora), or
/etc/network/interfaces (Debian classic). Runtime ip changes vanish on
reboot.
Loopback and 0.0.0.0 when binding
Which address a server binds decides who can reach it, and this is the single most common "works locally, not from another machine" bug.
| Bind address | Reachable from | Use when |
|---|---|---|
127.0.0.1 | only the same host | dev servers, DB behind a proxy |
0.0.0.0 | every IPv4 interface | containers, LAN services |
:: | every IPv6 interface, often IPv4 too via dual stack | modern servers |
| a specific IP | only that interface | multi-homed hosts, split traffic |
ss -lntp # listening TCP sockets with the owning process ss -lntp 'sport = :8080' # who holds a port
Public IP, ASNs, and who owns a prefix
Public space is delegated by IANA to five RIRs (ARIN, RIPE NCC, APNIC, LACNIC, AFRINIC) which assign it to organizations, each identified by an autonomous system number.
curl -s https://ifconfig.me # your egress public IP dig +short myip.opendns.com @resolver1.opendns.com whois 8.8.8.8 | grep -iE 'orgname|netname|cidr' whois -h whois.cymru.com " -v 8.8.8.8" # ASN, prefix, country
Your egress IP is not your interface IP when NAT is in the path, and both differ
from the address a load balancer or CDN shows the origin. That is what
X-Forwarded-For exists to carry.