IPv4 vs IPv6: Differences, NAT and What Changes in Your Code
IPv4 has 32 bits and ran out; IPv6 has 128 and needs no NAT. See the differences in one table and what changes in your bind call, database and logs.
I once lost an afternoon to a bug that only hit some users: the per-IP rate limit was blocking people who had never come close to the limit. The cause was mundane. The server listened on ::, IPv4 clients arrived as ::ffff:189.6.x.x, IPv6 clients arrived as 2804:..., and the code that normalized the IP only knew the dotted format. Half of the rate-limit key was garbage. Nobody on the team had thought about IPv6 because "that's an infra thing".
It isn't. This post compares IPv4 and IPv6 the way it matters to people who write code: the table of differences, why IPv4 ran out, where NAT fits in, and what changes in your bind call, your database and your logs. Public vs private, static vs dynamic IPs (and CGNAT from the user's side) live in the companion post Public, private, static and dynamic IP.
IPv4 vs IPv6: the table of differences
| IPv4 | IPv6 | |
|---|---|---|
| Address size | 32 bits | 128 bits |
| Notation | 4 decimal octets: 192.0.2.10 |
8 hex groups: 2001:db8::10 |
| Total addresses | 2³² ≈ 4.3 billion | 2¹²⁸ ≈ 3.4 × 10³⁸ |
| NAT | Everywhere (home, carrier, cloud) | Unnecessary: every device can have a global IP |
| Broadcast | Exists (255.255.255.255) |
Gone; uses multicast (ff02::1) |
| Header | 20 to 60 bytes, with checksum | Fixed 40 bytes, no checksum, extension headers |
| Configuration | Manual or DHCP | SLAAC (autoconfiguration), DHCPv6 optional |
| IPsec | Optional | Recommended (SHOULD), not mandatory |
| DNS record | A | AAAA |
| Loopback | 127.0.0.1 |
::1 |
| Private network | RFC 1918 (10/8, 172.16/12, 192.168/16) |
ULA (fc00::/7) |
The two protocols don't talk to each other. An IPv4-only host can't reach an IPv6-only host without some translation mechanism in between, which is why the internet runs dual-stack: both protocols side by side, possibly for a few more decades.
IPv4: 32 bits that ran out
An IPv4 address has 32 bits, written as four numbers from 0 to 255. That's 4,294,967,296 combinations, a number that looked generous when RFC 791 came out in 1981 and stopped looking that way long ago. Part of the space isn't even publicly usable: loopback (127.0.0.0/8), link-local (169.254.0.0/16), multicast (224.0.0.0/4) and the private ranges from RFC 1918.
IANA's central pool ran out in February 2011, when the last blocks went to the five regional registries. LACNIC, which serves Latin America and the Caribbean, exhausted its own pool in August 2020. Since then, anyone who needs new IPv4 space buys it on the secondary market or shares what they already have.
Sharing is NAT's job. Your home router swaps each device's private IP for its own public IP on the way out and reverses the swap on the way back. When even the carrier doesn't have a public IPv4 for every customer, it stacks one more NAT inside its own network: CGNAT. It works for browsing, but it breaks the internet's end-to-end model: inbound connections don't know which device to go to, and hosting anything needs port forwarding, a tunnel or a paid static IP. The port and forwarding details are in network ports.
IPv6: notation and what changes
An IPv6 address has 128 bits, written as eight groups of four hex digits:
2001:0db8:85a3:0000:0000:8a2e:0370:7334
2001:db8:85a3::8a2e:370:7334 # same address, abbreviated
Two abbreviation rules: leading zeros in each group can be dropped, and a single run of all-zero groups can become ::. The canonical form systems should emit (lowercase, always the shortest form) is defined in RFC 5952. That matters for string comparison: 2001:DB8::1 and 2001:0db8:0:0:0:0:0:1 are the same address.
There are 2¹²⁸ addresses, about 3.4 × 10³⁸. Divided by the Earth's surface (roughly 510 million km²), that's around 6.7 × 10²³ addresses per square meter. With that much room, every local network gets a whole /64 prefix and every device can have a global address, no NAT.
The address types you'll see in ip addr:
| Prefix | Type | IPv4 equivalent |
|---|---|---|
::1/128 |
Loopback | 127.0.0.1 |
fe80::/10 |
Link-local, self-configured on every interface | 169.254.0.0/16 |
fc00::/7 |
Unique Local (ULA), private network | RFC 1918 |
2000::/3 |
Global unicast (public) | Public IPs |
Some protocol differences also show up day to day. The IPv6 header is a fixed 40 bytes with no checksum (verification is left to the upper layers). There's no broadcast: what used to be broadcast becomes multicast. A device can build its own global address with SLAAC from the prefix the router advertises, without DHCP.
And a common myth: "IPv6 has mandatory IPsec". It did, in the original specification. RFC 6434, from 2011, downgraded IPsec support from MUST to SHOULD, and RFC 8504 (2019), which replaced it, kept the SHOULD. IPv6 isn't more secure than IPv4 by definition; encryption is still TLS, WireGuard or whatever you configure.
Why IPv6 adoption took so long
The first IPv6 specification is RFC 1883, from December 1995. It was revised by RFC 2460 (1998), and the current version is RFC 8200, from 2017. Three decades on, the migration is still halfway.
According to Google's data, which measures the share of users reaching its services over IPv6, global adoption swung between 47% and 51% in early November 2026, peaking on weekends (more traffic from homes and phones, less from corporate networks). In the same dataset, Brazil stood at 57.5% on November 7, 2026. These numbers move every week; check the page for the current value.
The reasons for the delay are well known. Turning on IPv6 doesn't turn off IPv4, so whoever migrates ends up running two stacks. NAT and the secondary market removed the urgency. And a lot of old equipment (routers, firewalls, embedded systems) couldn't do IPv6 without a hardware swap. Adoption was pulled forward by mobile carriers, which never had IPv4 for every phone, and by the big content providers.
What changes in your code
This is the part I wish I'd read before the rate-limit bug.
Binding to 0.0.0.0 vs ::. 0.0.0.0 listens on every IPv4 interface. :: listens on every IPv6 interface, and whether it also accepts IPv4 depends on the operating system. On Linux the default is yes: net.ipv6.bindv6only is 0, and a socket on :: receives IPv4 connections as ::ffff:a.b.c.d addresses. On Windows, Microsoft's documentation says the opposite: an IPv6 socket is IPv6-only by default, and you have to clear IPV6_V6ONLY before binding. I ran this in a Linux container:
// Node 22: with no host, listen tries "::" (and on Linux it accepts IPv4 too)
const net = require('net');
const srv = net.createServer(s => console.log(s.remoteAddress, s.remoteFamily));
srv.listen(3000, () => net.connect(3000, '127.0.0.1'));
// output: ::ffff:127.0.0.1 IPv6
# Python 3.8+: explicit dual-stack, no reliance on the OS default
import socket
srv = socket.create_server(("", 8000), family=socket.AF_INET6, dualstack_ipv6=True)
# client 127.0.0.1 shows up as ::ffff:127.0.0.1; client ::1 shows up as ::1
The practical consequence is my bug: the same IPv4 client can show up as 189.6.10.20 on one server and as ::ffff:189.6.10.20 on another. Normalize before using the IP as a key (rate limit, allowlist, audit trail). In Python, ipaddress.ip_address(x).ipv4_mapped returns the embedded IPv4; other languages have an equivalent.
Storage. In PostgreSQL, use the inet type (or cidr for networks): it takes both protocols and compares correctly. In MySQL, VARBINARY(16) with INET6_ATON() and INET6_NTOA(). If you insist on text, VARCHAR(39) fits the longest pure-hex IPv6 address (ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff) but not the unabbreviated form with an embedded IPv4, 0000:0000:0000:0000:0000:ffff:255.255.255.255, which is 45 characters. That's why C's INET6_ADDRSTRLEN constant is 46 (45 plus the terminator). Use 45 and stop thinking about it.
Parsing and logs. An IPv4 regex won't match IPv6, and a hand-written IPv6 regex almost always misses a case. Use your language's library (ipaddress in Python, net.ParseIP in Go, inet_pton in C). Watch out for host:port too: in IPv6 the colons are part of the address, so the correct form in URLs and logs is [2001:db8::1]:443, with brackets.
Per-IP rate limiting. In IPv4, one IP is usually one client (or a CGNAT full of them). In IPv6, a single client holds a whole /64 and may rotate addresses inside it on purpose, for privacy. Limiting by the full IPv6 address is useless; the usual practice is to group by /64 prefix.
DNS and Happy Eyeballs. To receive IPv6 traffic, the domain needs an AAAA record in addition to the A record (see DNS record types). When both exist, the client uses Happy Eyeballs, now specified in RFC 8305 (2017, which replaced RFC 6555): it tries IPv6 first and, if the connection doesn't come up within about 250 ms, starts IPv4 in parallel and keeps whichever answers first. If the domain has no AAAA, the client goes straight to IPv4 with no delay at all.
To find out whether your connection goes out over IPv4 or IPv6, I open What Is My IP: it shows your connection's public IP, its family and the provider (ASN). The same page has a CIDR calculator for IPv4 ranges and a converter that produces the IPv4-mapped address (::ffff:...) for an IPv4, handy for understanding what will show up in a dual-stack server's log.
Frequently asked questions
What is the main difference between IPv4 and IPv6?
Address size: 32 bits in IPv4 (about 4.3 billion addresses) versus 128 bits in IPv6 (about 3.4 × 10³⁸). The other differences follow from that: IPv6 does without NAT, replaces broadcast with multicast, has a fixed 40-byte header and supports autoconfiguration with SLAAC.
Is IPv6 faster than IPv4?
Not inherently. Speed depends on the path between the two ends. Without NAT in the way, IPv6 sometimes has slightly lower latency, and sometimes the IPv6 route is worse than the IPv4 one. On average the difference is small.
Does my site need IPv6?
It isn't mandatory: if the domain doesn't publish an AAAA record, every client uses IPv4 with no delay. But with IPv6 already carrying close to half of Google's global traffic, it's worth turning on. In most clouds it's a network setting plus an AAAA record. Only publish the AAAA after testing, because an AAAA pointing to a server that doesn't answer forces clients to wait for the fallback.
Why does my IP start with 192.168 or 10?
Those are RFC 1918 private addresses, valid only inside your local network. The IP websites see is the public one your router (or your carrier's CGNAT) uses on the way out. The difference between the two is covered in public vs private IP.
Handle both formats from the first commit
IPv4 ran out and survived thanks to NAT; IPv6 fixes the address shortage but lives alongside IPv4 in dual-stack, and your server receives both. For anyone writing code, the minimum is: know what your bind accepts on each operating system, store IPs in a native type (inet, VARBINARY(16)) or in 45-character text, normalize ::ffff: before using an IP as a key, and group IPv6 by /64 for rate limiting. If you want the full path of a request, from DNS to the first byte, the next step is how the internet works from DNS to HTTP.
- 01 CPU Cores vs. Threads: What Actually Changes in Practice Understand the difference between CPU cores and threads and what actually changes for performance, multitasking, gaming, and development.
- 02 MIT, Apache, and GPL Licenses: Practical Differences for Developers MIT, Apache 2.0, and GPL are not the same thing. Understand permissive vs copyleft, patent protection, and compatibility before shipping code to production.