← All tools

IP to Decimal Number Converter

Convert IPv4 and IPv6 addresses to decimal numbers (integers), hexadecimal and binary, or turn numbers back into IP addresses: one value or a list of up to 1,000.

One IPv4 or IPv6 address per line, up to 1,000.
Try:

How to convert an IP address to a decimal number

An IPv4 address is a 32-bit number written as four bytes separated by dots. To get its decimal value, multiply each byte by a power of 256 and add the results:

a.b.c.d = a × 256³ + b × 256² + c × 256 + d
192.168.1.1 = 192 × 16777216 + 168 × 65536 + 1 × 256 + 1 = 3232235777

IPv6 works the same way with 128 bits: eight groups of four hexadecimal digits make up one number that can be up to 39 decimal digits long.

How to convert a decimal number to an IP address

To go back, divide the number by 256 four times: each remainder is one byte, from the last to the first. 3232235777 leaves the remainders 1, 1, 168 and 192, which is 192.168.1.1. In the converter, switch to Number to IP and enter the number.

Why store an IP address as an integer

Numbers take less space than text and are easy to compare. An IPv4 address fits into a 4-byte integer column, and checking whether an address falls inside a range becomes a comparison of two numbers. IP geolocation databases, firewalls and access lists rely on exactly this. To get the first and last address of a network, use the CIDR to IP range converter.

IP to integer in MySQL, PHP, Python and JavaScript

-- MySQL
SELECT INET_ATON('192.168.1.1');   -- 3232235777
SELECT INET_NTOA(3232235777);      -- 192.168.1.1

// PHP
ip2long('192.168.1.1');   // 3232235777
long2ip(3232235777);      // 192.168.1.1

# Python
import ipaddress
int(ipaddress.ip_address('192.168.1.1'))   # 3232235777
str(ipaddress.ip_address(3232235777))      # 192.168.1.1

// JavaScript
'192.168.1.1'.split('.').reduce((n, o) => n * 256 + +o, 0);   // 3232235777
FAQ

Frequently asked questions

What is the largest number an IP address can be?

IPv4 addresses run from 0 (0.0.0.0) to 4,294,967,295 (255.255.255.255). IPv6 addresses go up to 2128 − 1, which is 340,282,366,920,938,463,463,374,607,431,768,211,455.

How do I store IPv6 addresses as numbers?

A 128-bit value does not fit into a regular 64-bit integer. Store it in a 16-byte binary column (BINARY(16)), in a DECIMAL(39,0) column, or split it into two 64-bit halves.

Does the converter accept hexadecimal numbers?

Yes. In Number to IP mode prefix the value with 0x, for example 0xC0A80101. A value that contains the letters a to f is read as hexadecimal even without the prefix.

Is the address I enter sent to your server?

No. The conversion runs entirely in your browser: nothing is transmitted or stored.

What is 192.168.1.1 as a decimal number?

192.168.1.1 is 3232235777, or 0xC0A80101 in hexadecimal. Other common addresses: 127.0.0.1 is 2130706433, 10.0.0.1 is 167772161 and 8.8.8.8 is 134744072.

Are IP to decimal, IP to integer and IP to long the same thing?

Yes. All three names describe the same conversion: the address written as one whole number. “Long” comes from the 32-bit long integer type and from functions such as ip2long() in PHP; MySQL calls the same operation INET_ATON().

Can I convert a list of IP addresses at once?

Yes. Paste up to 1,000 addresses or numbers, one per line; values separated by commas or spaces work too. The result is a table that you can copy whole or as a plain column of results, with one output line for every value you entered, so it stays aligned with your source list.