IP Address Validator
Validate IPv4 and IPv6 addresses and identify address types
About IP Addresses
An IP (Internet Protocol) address is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. IP addresses serve two main functions: host or network interface identification and location addressing. There are two versions of IP addresses currently in use: IPv4 and IPv6.
IPv4 Addresses
IPv4 (Internet Protocol version 4) uses 32-bit addresses, providing approximately 4.3 billion unique addresses:
- Format: Four decimal numbers (0-255) separated by dots
- Example: 192.168.1.1
- Range: 0.0.0.0 to 255.255.255.255
- Total Addresses: 2^32 = 4,294,967,296
IPv6 Addresses
IPv6 (Internet Protocol version 6) uses 128-bit addresses, providing a vastly larger address space:
- Format: Eight groups of four hexadecimal digits separated by colons
- Example: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
- Shortened: 2001:db8:85a3::8a2e:370:7334 (leading zeros and consecutive zero groups omitted)
- Total Addresses: 2^128 = 340 undecillion addresses
IPv4 Address Classes
| Class | Range | Purpose |
|---|---|---|
| Class A | 0.0.0.0 - 127.255.255.255 | Large networks (16 million hosts) |
| Class B | 128.0.0.0 - 191.255.255.255 | Medium networks (65,536 hosts) |
| Class C | 192.0.0.0 - 223.255.255.255 | Small networks (254 hosts) |
| Class D | 224.0.0.0 - 239.255.255.255 | Multicast |
| Class E | 240.0.0.0 - 255.255.255.255 | Reserved for future use |
Private IP Address Ranges (IPv4)
These addresses are reserved for use on private networks and are not routable on the public internet:
| Range | Number of Addresses | Typical Use |
|---|---|---|
| 10.0.0.0 - 10.255.255.255 | 16,777,216 | Large private networks |
| 172.16.0.0 - 172.31.255.255 | 1,048,576 | Medium private networks |
| 192.168.0.0 - 192.168.255.255 | 65,536 | Home and small office networks |
Special IPv4 Addresses
- 127.0.0.1: Loopback address (localhost)
- 0.0.0.0: Default route or unspecified address
- 255.255.255.255: Broadcast address
- 169.254.x.x: Link-local addresses (APIPA)
IPv6 Address Types
| Type | Prefix | Description |
|---|---|---|
| Global Unicast | 2000::/3 | Public addresses (routable on internet) |
| Link-Local | fe80::/10 | Local network communication only |
| Unique Local | fc00::/7 | Private addresses (like IPv4 private ranges) |
| Loopback | ::1/128 | Equivalent to 127.0.0.1 |
| Multicast | ff00::/8 | One-to-many communication |
When to Use IP Validation
- Network Configuration: Validate IP addresses in configuration files
- Firewall Rules: Ensure IP addresses in security rules are valid
- Log Analysis: Parse and validate IP addresses in server logs
- Access Control: Validate IP addresses for allowlists/blocklists
- API Development: Validate IP address parameters
- Network Monitoring: Check IP address validity in monitoring tools
CIDR Notation
CIDR (Classless Inter-Domain Routing) notation is used to specify IP address ranges:
- Format: IP_address/prefix_length
- Example: 192.168.1.0/24 represents 192.168.1.0 through 192.168.1.255
- /24: 256 addresses (254 usable hosts)
- /16: 65,536 addresses
- /8: 16,777,216 addresses
IPv4 vs IPv6 Comparison
| Feature | IPv4 | IPv6 |
|---|---|---|
| Address Length | 32 bits | 128 bits |
| Address Format | Decimal (192.168.1.1) | Hexadecimal (2001:db8::1) |
| Total Addresses | ~4.3 billion | ~340 undecillion |
| Header Size | 20-60 bytes | 40 bytes (fixed) |
| Fragmentation | By routers and hosts | Only by hosts |
Test IP Addresses
| Type | Example |
|---|---|
| IPv4 Private | 192.168.1.1 |
| IPv4 Public | 8.8.8.8 (Google DNS) |
| IPv4 Loopback | 127.0.0.1 |
| IPv6 Loopback | ::1 |
| IPv6 Link-Local | fe80::1 |
| IPv6 Global | 2001:4860:4860::8888 (Google DNS) |
Security Considerations
- Validate IP addresses in user input to prevent injection attacks
- Be cautious with private IP ranges in server-side request validation
- Block requests to localhost (127.0.0.1, ::1) from user input
- Consider blocking link-local addresses (169.254.x.x, fe80::)
- Implement rate limiting based on IP addresses
- Use IP geolocation for fraud detection
Best Practices
- Support both IPv4 and IPv6 in modern applications
- Normalize IPv6 addresses before storage or comparison
- Use IP validation libraries rather than regex when possible
- Log IP addresses for security and debugging purposes
- Consider using IP allowlists instead of blocklists
- Validate IP addresses on both client and server side
- Use proper data types for storing IP addresses in databases
Additional Resources
- IANA IPv4 Address Registry: iana.org/assignments/ipv4-address-space
- IANA IPv6 Address Registry: iana.org/assignments/ipv6-address-space
- RFC 791 (IPv4): tools.ietf.org/html/rfc791
- RFC 8200 (IPv6): tools.ietf.org/html/rfc8200