How 192.168.0.1 becomes 3232235521
An IPv4 address is four bytes. The dots are a display convention for people. Each byte sits in a fixed position, the first one carries the most weight, the last one the least.
- Split the address on the dots:
192,168,0,1. - Multiply the first octet by 16,777,216 (256 cubed): 3,221,225,472.
- Multiply the second by 65,536 (256 squared): 11,010,048.
- Multiply the third by 256: 0.
- Add the fourth as is: 1.
- Sum the four results: 3,232,235,521.
In code, bit shifts do the same job faster:
// JavaScript: >>> 0 forces an unsigned result
const n = ((a << 24) | (b << 16) | (c << 8) | d) >>> 0;
# Python
n = int(ipaddress.IPv4Address("192.168.0.1"))
Leave out the >>> 0 in JavaScript and every address from 128.0.0.0 upward comes back negative. The next section explains why.
The signed integer trap at 128.0.0.0
127.255.255.255 converts to 2,147,483,647, the largest value a signed 32-bit integer holds. One address later, 128.0.0.0 needs 2,147,483,648. A signed type wraps the value to -2,147,483,648.
Half of the IPv4 space sits above the line, including every 172.16 and 192.168 private address. The ones hit most often:
- Java
int. Read the value into along, or callInteger.toUnsignedLong(). - MySQL
INTwithoutUNSIGNED. Inserts above 2,147,483,647 fail in strict mode or clamp to the maximum in older non-strict setups. - PHP
ip2long()on 32-bit builds. Format withsprintf('%u', ...)to see the unsigned value. - C
int32_tor a plainintholdings_addr.
The converter above prints both forms. If your logs show -1062731775, you are looking at 192.168.0.1 stored in a signed column.
Private ranges as number boundaries
Once addresses are integers, a subnet is a closed interval. These bounds cover the reserved blocks you will filter on most:
| Block | First | Last |
|---|---|---|
| 10.0.0.0/8 | 167772160 | 184549375 |
| 100.64.0.0/10 carrier-grade NAT | 1681915904 | 1686110207 |
| 127.0.0.0/8 loopback | 2130706432 | 2147483647 |
| 169.254.0.0/16 link-local | 2851995648 | 2852061183 |
| 172.16.0.0/12 | 2886729728 | 2887778303 |
| 192.168.0.0/16 | 3232235520 | 3232301055 |
Need bounds for a block not listed here? Switch the converter to List or CIDR range, paste the block, pick SQL WHERE clause.
Storing addresses as integers in MySQL and PostgreSQL
MySQL ships the conversion as built-in functions. An INT UNSIGNED column takes 4 bytes per row, a VARCHAR(15) holding the dotted text takes up to 16, sorts as text, puts 10.0.0.9 after 10.0.0.10, and breaks range scans on the index.
CREATE TABLE access_log (
ip_num INT UNSIGNED NOT NULL,
seen_at DATETIME NOT NULL,
KEY (ip_num)
);
INSERT INTO access_log VALUES (INET_ATON('172.16.4.20'), NOW());
SELECT INET_NTOA(ip_num), seen_at
FROM access_log
WHERE ip_num BETWEEN 2886729728 AND 2887778303; -- 172.16.0.0/12
On PostgreSQL, skip integers. The native inet type stores IPv4 and IPv6 in one column, validates input, supports GiST indexes, checks containment with one operator. Integer columns there add conversion code with no gain.
SELECT * FROM access_log WHERE addr << inet '172.16.0.0/12';
What happens when you type 3232235521 into a browser
Chrome, Firefox, Safari follow the WHATWG URL rules, which read a host made of one number as an IPv4 address. curl accepts the same form. http://3232235521/ opens 192.168.0.1. http://2130706433/ opens 127.0.0.1.
The dotless form reaches the same machine as the dotted one. A blocklist matching on the string "127.0.0.1" lets 2130706433 through. If you review URL-fetching code for SSRF, test the integer form next to the dotted one. The IP to Octal Converter covers the leading-zero variant of the same bypass.
Where this converter stops
- IPv4 only. An IPv6 address is 128 bits, a number up to 39 digits long. JavaScript numbers lose precision past 2^53, so this page rejects IPv6 rather than print a wrong value. In MySQL, use
INET6_ATON()with aVARBINARY(16)column. - No leading zeros. 010 means 10 to some parsers and 8 to others. The tool refuses the octet instead of guessing.
- Big-endian order. The first octet carries the most weight, the order the network uses. Raw bytes read from memory on an x86 machine come out reversed, see the FAQ below.
- Range, not host list. CIDR lines return two numbers. To enumerate every address in a block, loop from the first to the last in your own code.
Going the other way, from a number back to dotted form, is a separate page: Decimal to IP Converter.