An IPv4 address is a 32-bit number
The familiar dotted form is just four bytes written in decimal. 192.168.1.1 is the bytes C0 A8 01 01, which read as one big-endian 32-bit number is 0xC0A80101 = 3,232,235,777. Each octet is multiplied by a power of 256: 192×256³ + 168×256² + 1×256 + 1.
- Take each octet in order: a, b, c, d.
- Compute a×16,777,216 + b×65,536 + c×256 + d.
- To go back, repeatedly divide by 256 and keep the remainders (or shift right by 8 and mask with 255).
Where the integer form is used
- Databases: MySQL
INET_ATON()/INET_NTOA()and PostgreSQLinetstore and index addresses as numbers so range queries (ip BETWEEN start AND end) are fast. GeoIP tables use the same trick. - Programming: C
inet_aton, PHPip2long, Pythonint(ipaddress.ip_address(x)), Gobinary.BigEndian.Uint32(ip.To4()). - Access lists and firewalls, which compare the number against a mask.
Odd forms browsers accept
Because the address is a number, http://3232235777/ and http://0xC0A80101/ both reach 192.168.1.1 in most browsers, and 192.168.257 is parsed as 192.168.1.1 (the last part spills into the previous octet). These are a classic way to hide an address in a phishing link, and a reason to validate input strictly, as this tool does.
Questions
What is 192.168.1.1 as an integer?
3,232,235,777 in decimal, 0xC0A80101 in hex. It comes from 192×256³ + 168×256² + 1×256 + 1.
Why would I store IP addresses as integers?
An integer takes 4 bytes instead of up to 15 characters, sorts in network order, and lets you test membership in a range with two comparisons. Most GeoIP and firewall data is stored this way.
What is the largest IPv4 integer?
4,294,967,295 (2³² − 1), which is 255.255.255.255.
Does this work for IPv6?
IPv6 addresses are 128-bit numbers and need a different tool: use the IPv6 calculator, which shows the expanded, compressed and binary forms.
Is 192.168.001.001 the same as 192.168.1.1?
Not reliably. Some parsers treat an octet with a leading zero as octal (001 is fine, but 010 would be 8). Write octets without leading zeros to avoid the ambiguity; this tool rejects them for that reason.