IPv6 addresses are much bigger than IPv4 addresses, and your code must handle both formats.
IPv4 addresses are 32 bits. They are written as four decimal numbers, like 203.0.113.10. That gives about 4.3 billion addresses. They ran out long ago, which led to heavy use of NAT (routers sharing one public address between many devices).
IPv6 addresses are 128 bits. They are written as eight groups of hex digits, like 2001:db8::1. Here :: stands for a run of groups that are all zero. The space is big enough for every device to have its own globally routable address.
Practical points:
- Loopback is
127.0.0.1in IPv4 and::1in IPv6.localhostmay resolve to either one. So a server that listens only on127.0.0.1won't accept a client that connects to::1. - In URLs, IPv6 addresses need square brackets, as in
http://[::1]:3000. - Listening on
::usually accepts IPv4 clients too, as IPv4-mapped addresses. This depends on the OS's dual-stack setting. - Code that logs, rate-limits or allow-lists IPs must handle both formats.
- IPv4 is 32-bit. IPv6 is 128-bit, written in hex, with :: to shorten zero groups.
- Running out of IPv4 addresses drove the use of NAT.
- Loopback is 127.0.0.1 in IPv4 and ::1 in IPv6, and localhost may resolve to either.
- IPv6 addresses in URLs need square brackets.
- IP parsing in apps must handle both formats.
Read more
- IPv6 (MDN) (https://developer.mozilla.org/en-US/docs/Glossary/IPv6)developer.mozilla.org
- IPv6 (https://en.wikipedia.org/wiki/IPv6)en.wikipedia.org