IP Addressing — IPv4 & IPv6
BeginnerAn IP address is a logical identifier assigned to every network interface. IPv4 uses 32-bit addresses (4.3 billion); IPv6 uses 128-bit addresses to solve exhaustion. Both coexist today via dual-stack.
Overview
Every device on a network needs a unique logical address to send and receive packets — that is the IP address. IPv4 uses 32-bit addresses written in dotted-decimal notation (e.g., 192.168.1.10), providing ~4.3 billion unique addresses — exhausted by 2011. IPv6 uses 128-bit addresses written in hexadecimal (e.g., 2001:db8::1), providing 3.4×10³⁸ addresses. Addresses are divided into a network portion (identifies the network) and a host portion (identifies the device). Private address ranges (RFC 1918) — 10.x.x.x, 172.16–31.x.x, 192.168.x.x — are not routable on the public internet and are used inside LANs and cloud VPCs. Special addresses include 127.0.0.1 (loopback), 0.0.0.0 (any interface), and 255.255.255.255 (broadcast). For backend engineers, IP address knowledge is essential for configuring cloud networking, firewalls, Kubernetes pod networks, and debugging connectivity.
IPv4 Address Classes and Private Ranges
IPv4 addresses are 32 bits, split into network and host parts. Private ranges are reserved for internal use and NATted to public IPs when accessing the internet. Knowing private ranges helps when configuring VPCs, security groups, and firewall rules.
// IPv4 address = 32 bits = 4 octets
// Example: 192.168.1.10
// Binary: 11000000.10101000.00000001.00001010
// Private address ranges (RFC 1918) — NOT routable on internet:
// 10.0.0.0 – 10.255.255.255 (10.0.0.0/8) — Class A, 16M hosts
// 172.16.0.0 – 172.31.255.255 (172.16.0.0/12) — Class B, 1M hosts
// 192.168.0.0 – 192.168.255.255 (192.168.0.0/16)— Class C, 65K hosts
// Special addresses:
// 127.0.0.1 — loopback (localhost)
// 0.0.0.0 — "any" interface (bind all)
// 255.255.255.255 — limited broadcast
// 169.254.x.x — APIPA (auto-assigned when DHCP fails)
// Java: get all local IP addresses
NetworkInterface.getNetworkInterfaces().asIterator().forEachRemaining(iface -> {
iface.getInetAddresses().asIterator().forEachRemaining(addr -> {
System.out.println(iface.getName() + " → " + addr.getHostAddress());
});
});
// Typical output:
// lo → 127.0.0.1
// eth0 → 10.0.1.5 (private IP in cloud VPC)IPv6 — Structure and Coexistence
IPv6 addresses are 128 bits written as 8 groups of 4 hex digits. Consecutive zero groups are compressed with "::". Dual-stack hosts run both IPv4 and IPv6 simultaneously. IPv6 eliminates NAT — every device gets a globally routable address.
// IPv6 address = 128 bits = 8 groups of 4 hex digits
// Full: 2001:0db8:0000:0000:0000:ff00:0042:8329
// Compressed:2001:db8::ff00:42:8329 (:: replaces longest run of zeros)
// Special IPv6 addresses:
// ::1 — loopback (equivalent to 127.0.0.1)
// fe80::/10 — link-local (auto-configured, not routed)
// fc00::/7 — unique local (private, like RFC 1918)
// 2001:db8::/32 — documentation/examples only
// ::ffff:0:0/96 — IPv4-mapped IPv6 (::ffff:192.168.1.1)
// Java: resolve both IPv4 and IPv6
InetAddress[] addresses = InetAddress.getAllByName("google.com");
for (InetAddress addr : addresses) {
if (addr instanceof Inet4Address) {
System.out.println("IPv4: " + addr.getHostAddress()); // e.g. 142.250.80.46
} else if (addr instanceof Inet6Address) {
System.out.println("IPv6: " + addr.getHostAddress()); // e.g. 2a00:1450:4009:81a::200e
}
}
// Dual-stack: Spring Boot listens on both by default
// server.address=0.0.0.0 → binds all IPv4 interfaces
// server.address=:: → binds all IPv6 interfaces (also serves IPv4 on most OS)Key Points to Remember
- 1IPv4: 32-bit, ~4.3B addresses. IPv6: 128-bit, 3.4×10³⁸ addresses.
- 2Private IPv4 ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 — not internet-routable.
- 3Loopback: 127.0.0.1 (IPv4), ::1 (IPv6). Bind-all: 0.0.0.0 (IPv4), :: (IPv6).
- 4IPv6 uses :: to compress consecutive zero groups.
- 5Dual-stack hosts run IPv4 and IPv6 simultaneously — modern OSes prefer IPv6 when available.
- 6IPv6 eliminates NAT — every device gets a globally unique address.
Interview Questions
Sign in to ask AriaWhat are private IP address ranges and why are they not routable on the internet?
What is the difference between IPv4 and IPv6?
Why was IPv6 introduced and what problem does it solve?
What is a dual-stack host and how does it handle both IPv4 and IPv6?
What is the significance of 0.0.0.0 when binding a server socket?
Ask Aria about IP Addressing — IPv4 & IPv6
Your personal AI tutor — ask anything about this concept
Revision Status
Personal Notes
Sign in to save personal notes for this topic.
Discussion
Sign in to join the discussion.