IP Addressing (IPv4 & IPv6)

beginner ip ipv4 ipv6 addressing networking

An IP address is a unique identifier for a device on a network. Like a postal address, but for packets. Two flavors exist today: IPv4 (the old one) and IPv6 (the bigger one).

In simple language: every machine that wants to send or receive on the internet needs an IP address — that’s how routers know where to deliver our packets.

IPv4 — Dotted Decimal

IPv4 addresses are 32 bits, written as four numbers (0–255) separated by dots:

192.168.1.10
  |   |   |   |
  8b  8b  8b  8b   = 32 bits total

That gives us about 4.3 billion unique addresses (2^32). Sounds like a lot — until we realize there are 8 billion humans plus phones, IoT devices, servers, etc. We ran out years ago. NAT and IPv6 are the rescue plans.

IPv4 Classes (Historical)

Originally, IPv4 was split into classes based on the first octet:

Class A:  1.0.0.0    - 126.255.255.255    (huge networks, 8-bit prefix)
Class B:  128.0.0.0  - 191.255.255.255    (medium, 16-bit prefix)
Class C:  192.0.0.0  - 223.255.255.255    (small, 24-bit prefix)
Class D:  224.0.0.0  - 239.255.255.255    (multicast)
Class E:  240.0.0.0  - 255.255.255.255    (reserved)

Classes are deprecated — modern networks use CIDR (covered in the next note). But interviewers still ask, so know the ranges.

Private IP Ranges (RFC 1918)

These ranges are reserved for private networks — they don’t get routed on the public internet:

10.0.0.0    /8    -> 10.0.0.0    – 10.255.255.255    (16M addresses)
172.16.0.0  /12   -> 172.16.0.0  – 172.31.255.255    (1M addresses)
192.168.0.0 /16   -> 192.168.0.0 – 192.168.255.255   (65K addresses)

That’s why our home router gives us something like 192.168.1.42. Outside of our LAN, we’re known by our public IP (assigned by the ISP) thanks to NAT.

Special IPs Worth Knowing

127.0.0.1            -> loopback (this machine itself, "localhost")
0.0.0.0              -> "any IP" (used to bind to all interfaces)
255.255.255.255      -> broadcast (everyone on the LAN)
169.254.x.x          -> link-local (auto-assigned when DHCP fails)

IPv6 — The Bigger Address Space

IPv6 addresses are 128 bits — written as eight groups of 4 hex digits separated by colons:

2001:0db8:85a3:0000:0000:8a2e:0370:7334

That’s 2^128 addresses, or roughly 340 undecillion. Enough to give every grain of sand on Earth its own IP and still have plenty left over.

IPv6 Shorthand

Long IPv6 is painful to type. We can shorten it:

  1. Drop leading zeros in each group: 2001:db8:85a3:0:0:8a2e:370:7334
  2. Replace one run of all-zero groups with ::: 2001:db8:85a3::8a2e:370:7334

The :: shortcut can only appear once in an address (otherwise we couldn’t tell how many zero groups it represents).

Common IPv6 Special Addresses

::1            -> loopback (IPv6 version of 127.0.0.1)
::             -> unspecified ("any")
fe80::/10      -> link-local (similar to 169.254.x.x in v4)
fc00::/7       -> unique local (private, like RFC 1918)
2000::/3       -> global unicast (the public internet)

Why IPv6 If We Have NAT?

NAT works, but it’s a hack:

  • Breaks end-to-end connectivity (peer-to-peer apps suffer).
  • Makes server hosting from a home network awkward.
  • Adds latency and state at every gateway.

IPv6 gives every device a real, routable address. No NAT needed.

Checking Your Own IPs

# Linux / macOS — see all interfaces
ip addr           # Linux
ifconfig          # macOS

# Just your public IP
curl ifconfig.me
curl -4 ifconfig.me   # force IPv4
curl -6 ifconfig.me   # force IPv6

# On Windows
ipconfig /all

Adoption Reality

IPv6 adoption has crept up — Google measures roughly 40%+ of users reaching them over IPv6 in 2025. Big networks (mobile carriers, datacenters) are mostly there. Lots of legacy infra still runs IPv4 + NAT, so we’ll be juggling both for a long time.

Interview Tip

Two facts that come up often: 127.0.0.1 = localhost = ::1, and the three private IPv4 ranges. If asked “why do we need IPv6?” — say “IPv4 exhaustion” and bonus points for mentioning NAT trade-offs.