How to convert between IPv4 addresses and 32-bit integers

This page turns a dotted-decimal IPv4 address into the unsigned 32-bit number its four octets encode, and turns such a number back into dotted notation. 192.168.10.1 becomes 3232238081, and 3232238081 returns 192.168.10.1.

Both directions run in the browser tab and the address is not uploaded. A value that is not a valid dotted IPv4 address or a whole number from 0 to 4294967295 is refused with a sentence that names the problem, instead of being converted into a wrong answer.

  1. Type or paste a dotted IPv4 address such as 192.168.10.1, or a whole number such as 3232238081. Load example fills in 192.168.10.1.
  2. Press IPv4 → Integer to read an address as a number, or Integer → IPv4 to go back. The page does not guess the direction from the input, which is why there are two buttons.
  3. Read the result in the second field: either a decimal integer or a dotted address, with no padding or separators.
  4. Press Copy result to put the value on the clipboard, or Clear to empty both fields and start again.
  5. When input is refused, the note above the buttons says why: octet count, octet range, a leading zero, a sign, a decimal point, an exponent, or a value outside 0–4294967295.

What the conversion does, and what it refuses

Why the number matches the address

An IPv4 address is a 32-bit number written as four decimal octets. The value follows network byte order, so the first octet is the most significant byte: it is multiplied by 16,777,216 (256³), the second by 65,536, the third by 256 and the last by 1. That is how 192.168.10.1 becomes 3232238081, and why the ends of the range are 0.0.0.0 = 0 and 255.255.255.255 = 4294967295.

Databases and network APIs store addresses this way because one integer compares, sorts and indexes faster than a string: PHP's ip2long() and MySQL's INET_ATON() return the same value shown here (verified on the server that runs this page). The number is unsigned; the same 32 bits read as a signed integer would be negative from 128.0.0.0 (2147483648) upwards.

Accepted and refused input

An address needs exactly four decimal octets separated by dots, each from 0 to 255 and written without leading zeros: 192.168.010.1 is refused because the leading zero makes the octet ambiguous. Three octets, a fifth octet, letters or a space inside the value are refused as well — the five-octet form 192.168.10.1.5 used to be accepted while the last part was silently ignored.

The number form needs plain decimal digits, with no sign, decimal point or exponent: -1, 1.5 and 3.232238081e9 are all refused, as is anything above 4294967295. The page converts IPv4 only; IPv6 addresses such as ::1, a prefix length such as /24 and hexadecimal or octal notation are reported as invalid input rather than guessed at.

Reading and reusing the result

The output is deliberately plain: a decimal integer with no thousands separators, or a dotted address with no leading zeros, ready to paste into SQL, a configuration file or code. Use Copy result rather than selecting the text by hand; the copy happens in the browser and needs no upload.

Nothing is sent to a server, so the conversion also works with the network disconnected once the page has loaded, and the same value can be checked with ip2long(), INET_ATON() or inet_aton(). The result field holds one value at a time: each conversion replaces it, and Clear empties both fields.

Recent tools: