IP to Decimal Converter

Type an IPv4 address, get the single 32-bit number behind the dots. 192.168.0.1 is 3232235521. Store the number in a 4-byte column, sort addresses in true numeric order, test subnet membership with two comparisons.

Converts as you type. Four octets, 0 to 255, no leading zeros.
Unsigned integer  
Signed 32-bit Java int, int32_t
 
Hex
 
Dotless URL
 

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.

  1. Split the address on the dots: 192, 168, 0, 1.
  2. Multiply the first octet by 16,777,216 (256 cubed): 3,221,225,472.
  3. Multiply the second by 65,536 (256 squared): 11,010,048.
  4. Multiply the third by 256: 0.
  5. Add the fourth as is: 1.
  6. 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 a long, or call Integer.toUnsignedLong().
  • MySQL INT without UNSIGNED. 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 with sprintf('%u', ...) to see the unsigned value.
  • C int32_t or a plain int holding s_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:

BlockFirstLast
10.0.0.0/8167772160184549375
100.64.0.0/10 carrier-grade NAT16819159041686110207
127.0.0.0/8 loopback21307064322147483647
169.254.0.0/16 link-local28519956482852061183
172.16.0.0/1228867297282887778303
192.168.0.0/1632322355203232301055

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 a VARBINARY(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.

Questions about IP integers

Byte order, sign bits, CIDR masking.

Why does my code show a negative number for 192.168.0.1?

The value went into a signed 32-bit type. 192.168.0.1 is 3232235521 unsigned, which is larger than 2147483647, so a signed int stores -1062731775 instead. Add 4294967296 to any negative result to recover the unsigned number, or switch the column or variable to an unsigned or 64-bit type.

I read 16820416 for 192.168.0.1 from a C struct. Which number is right?

Both describe the same four bytes in opposite order. 3232235521 is network byte order, first octet most significant. 16820416 is what you get when an x86 machine reads those bytes as a little-endian integer, which equals 1.0.168.192 in dotted form. Call ntohl() on s_addr before printing, or compare against this tool in big-endian terms.

Why did 192.168.10.77/24 return the same range as 192.168.10.0/24?

A /24 prefix fixes the first 24 bits and leaves the last 8 free. The converter clears those free bits to find the block start, then sets them all to find the end. The host part you typed, 77, falls inside the block and does not change the bounds.

Is there a decimal form for IPv6 addresses?

Yes, but the number runs up to 340282366920938463463374607431768211455, far past what a 64-bit column or a JavaScript number holds. Databases store IPv6 as 16 raw bytes instead. This page handles IPv4 only.

Does the page send my addresses to a server?

No. Single and bulk conversions both run in your browser. Nothing you paste leaves the tab.