Networking Tutorial · Networking Basics · Lesson 4 of 28

IP Addresses (IPv4)

How IPv4 addresses are written, public versus private ranges, and special addresses you'll meet in the cloud.

Create a free account to save this page, take notes and track your progress. Sign in

What is an IP address?

An IPv4 address is a 32-bit number identifying a network interface, written as four bytes in decimal: 192.168.1.20. Each part is 0 to 255. There are about 4.3 billion IPv4 addresses, which is not enough for every device on earth. That shortage is why private addresses, NAT and IPv6 exist.

An IPv4 address is a 32-bit numberTry it yourself
import ipaddress

ip = ipaddress.ip_address("192.168.1.20")
print("as a number:", int(ip))
print("in binary:  ", ".".join(f"{b:08b}" for b in ip.packed))
print("next address:", ip + 1)

Output

as a number: 3232235796
in binary:   11000000.10101000.00000001.00010100
next address: 192.168.1.21

Private and special ranges

Range Meaning
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 Private (RFC 1918): free to use inside any network, not routed on the internet
100.64.0.0/10 Carrier-grade NAT (shared address space used by internet providers)
127.0.0.0/8 Loopback: 127.0.0.1 is "this machine" (localhost)
169.254.0.0/16 Link-local. The cloud metadata service lives at 169.254.169.254
0.0.0.0 "Any address": a server listening on 0.0.0.0 accepts connections on every interface
everything else (mostly) Public: globally unique and routable on the internet

Cloud networks (VPCs) are built from private ranges, usually somewhere in 10.0.0.0/8.

Classify addressesTry it yourself
import ipaddress

for text in ["10.20.1.5", "172.31.0.10", "8.8.8.8", "127.0.0.1", "169.254.169.254", "100.64.3.1"]:
    ip = ipaddress.ip_address(text)
    kind = ("loopback" if ip.is_loopback else "link-local" if ip.is_link_local
            else "private" if ip.is_private else "shared (CGNAT)" if ip in ipaddress.ip_network("100.64.0.0/10")
            else "public")
    print(f"{text:16} {kind}")

Output

10.20.1.5        private
172.31.0.10      private
8.8.8.8          public
127.0.0.1        loopback
169.254.169.254  link-local
100.64.3.1       shared (CGNAT)

Test yourself

Which address is a private (RFC 1918) address?

  1. 8.8.4.4
  2. 172.20.5.9
  3. 172.32.0.1
  4. 100.64.0.1
Show answer

Answer: 172.20.5.9

172.16.0.0/12 covers 172.16.0.0 to 172.31.255.255, so 172.20.5.9 is private and 172.32.0.1 is not. 100.64.0.0/10 is shared address space for carrier-grade NAT, not RFC 1918.

Was this page helpful?