IPv4 to Decimal Converter
Type an IPv4 address or a whole number. Get the other form at once, along with hex, octal and binary, and the one-liners that do the same conversion in SQL and code.
Runs entirely in your browser — nothing you enter here is sent to a server.
Why an IP address is also a number
An IPv4 address is 32 bits. The dotted form — four numbers from 0 to 255 — is only a readable way to write those bits, one byte at a time. Read all 32 bits as a single whole number and you get the decimal form: 192.168.1.10 is 192×256³ + 168×256² + 1×256 + 10 = 3232235786. The two forms name exactly the same address, and so do the hexadecimal and binary ones.
Storing addresses
A 4-byte unsigned integer takes less room than a 15-character string and sorts in address order.
Range checks
"Is this address inside that network?" becomes one comparison: first ≤ address ≤ last.
Geolocation tables
IP-to-country databases list ranges as pairs of integers, so lookups need the decimal form.
Reading logs
Some firewalls and applications log addresses as integers or hex. Convert them back here.
Doing the conversion in code
Every platform has a pair of functions for this: INET_ATON() and INET_NTOA() in MySQL, ip2long() and long2ip() in PHP, the ipaddress module in Python, inet_pton() in C. Keep the value unsigned: on a 32-bit signed type every address from 128.0.0.0 upwards turns negative, which breaks comparisons. In MySQL use INT UNSIGNED; in PostgreSQL the inet type stores addresses properly without any conversion.
The same number also works as a URL in many browsers — http://3232235786/ opens 192.168.1.10. That is a common way to disguise a link, and a good reason to convert any odd-looking numeric host before clicking it.
Frequently asked questions
How do I convert an IP address to decimal by hand?
Multiply the first number by 16,777,216, the second by 65,536, the third by 256, and add the fourth. For 10.0.0.1 that is 10 × 16,777,216 + 1 = 167,772,161.
What is the largest decimal IPv4 address?
4,294,967,295, which is 255.255.255.255 — 32 bits all set. The smallest is 0, which is 0.0.0.0.
Why does my database show a negative number for an IP?
The column is a signed 32-bit integer, so addresses from 128.0.0.0 upwards overflow into negative values. Use an unsigned column, or a 64-bit integer.
Can I convert IPv6 addresses the same way?
Yes, but the number is 128 bits and too large for ordinary integer types. Use the IPv6 decimal converter, and store IPv6 as 16 bytes of binary.