IP Address to Integer Converter (IPv4 & IPv6)

Type an IPv4 or IPv6 address, or a number in decimal, hexadecimal, octal or binary: the kind is detected and every other representation is shown. A bulk mode converts a whole list.

Loading tool…

About the IP to Integer

An IPv4 address is a 32-bit number written as four bytes: 192.168.10.37 is 192·224 + 168·216 + 10·28 + 37 = 3232238117, or 0xC0A80A25. Databases and logs often store the number because it takes 4 bytes instead of up to 15 characters and makes range queries (BETWEEN) fast. Use an unsigned 32-bit column: a signed one overflows above 127.255.255.255. An IPv6 address is a 128-bit number, too large for the integer types of most languages and databases, so the converter uses arbitrary-precision integers and also shows the high and low 64-bit halves.

The classic inet_aton() function — and therefore ping, curl and the URL parser of every browser — accepts more than dotted decimal: each part may be hexadecimal (0xC0.0xA8.0x0A.0x25) or octal with a leading zero (0300.0250.012.045), and with fewer than four parts the last one fills the remaining bytes, so 192.168.2597, 127.1 and the plain number 3232238117 are all valid hosts. These forms are recognised on input. They matter for security reviews: a filter that blocks 127.0.0.1 as text can be bypassed with 2130706433 or 017700000001.

For each address you also get the IPv4-mapped IPv6 form (::ffff:192.168.10.37, the way dual-stack sockets report IPv4 clients), the 6to4 prefix, the reverse DNS name and the address type. The reference panel shows the equivalent calls for the current value: INET_ATON(), INET_NTOA() and INET6_ATON() in MySQL and MariaDB, the inet type in PostgreSQL, ipaddress in Python, ip2long() in PHP. Nothing is sent to a server.

How to use it

  1. Type or paste an IP address or a number; the detected kind is shown next to the field.
  2. Choose “Read numbers as IPv6” if a small number such as 1 should become ::1 instead of 0.0.0.1.
  3. Copy the representation you need, or the SQL / code line from the reference panel.
  4. For a list, paste one value per line into the bulk converter and choose the output form.

Frequently asked questions

How do I convert an IP address to an integer by hand?
Multiply the four parts by 16777216, 65536, 256 and 1 and add them: 192.168.10.37 is 192×16777216 + 168×65536 + 10×256 + 37 = 3232238117. To go back, divide by 256 repeatedly and keep the remainders.
Why does 192.168.010.001 give a different address than expected?
In inet_aton notation a part with a leading zero is octal, so 010 is 8 and the address is 192.168.8.1. Parts with the digits 8 or 9 after a leading zero are invalid. Strict parsers, such as Python's ipaddress module, reject leading zeros for this reason.
Which column type should I use to store IP addresses?
In MySQL use INT UNSIGNED with INET_ATON() for IPv4, or VARBINARY(16) with INET6_ATON() for both families. PostgreSQL has the inet and cidr types, which handle IPv4 and IPv6 and support containment operators. Avoid signed 32-bit integers.
What is an IPv4-mapped IPv6 address?
An address in ::ffff:0:0/96 whose last 32 bits are an IPv4 address, e.g. ::ffff:192.0.2.1 (also written ::ffff:c000:201). Operating systems use it to show IPv4 connections on IPv6 sockets; it is not routed on the Internet.

Related tools