IP to decimal converter
Convert an IPv4 address to its 32-bit decimal number, hexadecimal, binary and octal forms, or paste a decimal number to get the dotted address back.
| Decimal | 3232235777 |
|---|---|
| Hexadecimal | 0xC0A80101 |
| Binary | 11000000.10101000.00000001.00000001 |
| Octal | 030052000401 |
| Dotted hex | 0xc0.0xa8.0x01.0x01 |
The working
192 × 16,777,216 + 168 × 65,536 + 1 × 256 + 1 × 1 = 3,232,235,777
In code
- MySQL:
SELECT INET_ATON('192.168.1.1'), INET_NTOA(3232235777); - Python:
int(ipaddress.IPv4Address('192.168.1.1')) - JavaScript:
ip.split('.').reduce((a, o) => a * 256 + +o, 0)(avoid<<, which overflows to negative numbers above 127.x.x.x). - PostgreSQL:
SELECT '192.168.1.1'::inet - '0.0.0.0'::inet;
Questions people ask
How do I convert an IP address to decimal?
Multiply each octet by its place value and add: a × 16,777,216 + b × 65,536 + c × 256 + d. For 192.168.1.1: 192 × 16,777,216 + 168 × 65,536 + 1 × 256 + 1 = 3,232,235,777.
How do I convert decimal back to an IP?
Divide by 16,777,216 for the first octet, take the remainder and divide by 65,536 for the second, then by 256 for the third; the last remainder is the fourth octet.
Why would I need the decimal form?
Databases store IPs as 32-bit integers for fast range queries (MySQL's
INET_ATON(), PostgreSQL's inet type internally), GeoIP files use integer ranges, and some URL filters accept http://3232235777/, which attackers use to disguise addresses.