IP ⇄ Number Converter

Convert IPv4 addresses to decimal numbers and decimal numbers back to IP.

Back to all tools on ToolForge

More in Web & Network

IP Address



Number

About IP ⇄ Number Converter

This converter transforms IPv4 addresses to 32-bit decimal numbers and decimal numbers back to IP. Useful for database storage, range comparisons and IP arithmetic.

IP to Number Conversion Formula

// IP to Number
function ipToNumber(ip) {
  const parts = ip.split('.');
  return (parseInt(parts[0]) * 16777216) +
         (parseInt(parts[1]) * 65536) +
         (parseInt(parts[2]) * 256) +
         parseInt(parts[3]);
}

// Number to IP
function numberToIp(num) {
  return ((num >> 24) & 255) + '.' +
         ((num >> 16) & 255) + '.' +
         ((num >> 8) & 255) + '.' +
         (num & 255);
}

// Example: 192.168.1.1 → 3232235777
// 192 * 16777216 = 3221225472
// 168 * 65536 = 11010048
// 1 * 256 = 256
// 1 = 1
// Total = 3232235777

Common IP Address Ranges

Range IP Range Number Range Use
Private A 10.0.0.0 - 10.255.255.255 167772160 - 184549375 Private networks
Private B 172.16.0.0 - 172.31.255.255 2886729728 - 2887778303 Private networks
Private C 192.168.0.0 - 192.168.255.255 3232235520 - 3232301055 Home networks
Loopback 127.0.0.0 - 127.255.255.255 2130706432 - 2147483647 Localhost
Link-local 169.254.0.0 - 169.254.255.255 2851995648 - 2852061183 Auto-configuration

Frequently Asked Questions

How is an IP address converted to a number?
An IPv4 address is converted to a number by treating each octet as an 8-bit value and combining them: number = (octet1 × 256³) + (octet2 × 256²) + (octet3 × 256) + octet4. For example, 192.168.1.1 becomes (192×16777216) + (168×65536) + (1×256) + 1 = 3232235777.
What is the range of valid IP numbers?
IPv4 numbers range from 0 to 4,294,967,295 (2³² - 1). This represents all possible 32-bit values. 0.0.0.0 equals 0, and 255.255.255.255 equals 4,294,967,295. Numbers outside this range are invalid for IPv4.
Why store IP addresses as numbers?
Storing IPs as numbers is more efficient for databases (4 bytes vs 15 characters), enables fast range queries (BETWEEN 167772160 AND 184549375), simplifies IP arithmetic, and allows efficient indexing. Many geolocation and firewall systems use numeric IP storage.
How do I convert a number back to IP format?
Extract each octet using bit shifting: octet1 = (number >> 24) & 255, octet2 = (number >> 16) & 255, octet3 = (number >> 8) & 255, octet4 = number & 255. For example, 3232235777 becomes 192.168.1.1.