IPv4 ↔ Integer Converter

Convert IPv4 addresses to/from 32-bit integers

Input IPv4 Addresses

Converts IPv4 addresses to their 32-bit unsigned integer representation.

Conversion Results

Conversion results will appear here

The IPv4 to Integer Converter transforms IPv4 addresses between dotted-decimal notation (e.g., 192.168.1.1) and their 32-bit unsigned integer representation (e.g., 3232235777). Enter either format and get the instant conversion with intermediate calculation steps, hexadecimal equivalent, and binary breakdown showing how each octet contributes to the final value.

Understanding IPv4 Integer Representation

Under the hood, every IPv4 address is just a 32-bit number. The dotted-decimal notation we use every day -- 192.168.1.1 -- is a human-friendly way of writing that number by splitting the 32 bits into four 8-bit chunks (octets) and showing each one as a decimal value from 0 to 255. The integer form is the same number written as a single value, which for 192.168.1.1 is 3,232,235,777. Both representations point to exactly the same address; the only difference is how we write it down.

The integer form matters in practice because computers work with numbers, not dotted strings. When you store an IP address in a database, string storage works but wastes space and makes range queries unreliable. A VARCHAR(15) column uses up to 15 bytes, while an INT UNSIGNED uses exactly 4 bytes -- a 70% reduction. More importantly, string comparison produces wrong results for range queries: the string "9.0.0.0" sorts after "10.0.0.0" alphabetically, even though the address 9.0.0.0 comes before 10.0.0.0 numerically. Integer storage fixes both problems at once.

This conversion also unlocks simple arithmetic for address manipulation. Want to know if an address falls within a subnet? Convert the address, the network address, and the broadcast address to integers, then check if the address integer falls between the other two. Want to generate all addresses in a range? Start at the first integer and increment until you reach the last. Want to find the next available address after a given one? Just add one to the integer. All of these operations are trivial with integers and awkward with dotted-decimal strings.

How to Convert IPv4 to Integer (and Back)

  1. Enter an IPv4 address in dotted-decimal format or a 32-bit unsigned integer (0 to 4294967295)
  2. Click Convert to see the equivalent representation in the other format
  3. View the intermediate calculation showing how each octet contributes to the integer value

IPv4 to Integer Conversion Examples

IPv4 AddressIntegerHex
0.0.0.000x00000000
0.0.0.110x00000001
1.0.0.0167772160x01000000
10.0.0.11677721610x0A000001
127.0.0.121307064330x7F000001
172.16.0.128867297290xAC100001
192.168.0.132322355210xC0A80001
192.168.1.132322357770xC0A80101
192.168.1.25532322360310xC0A801FF
255.255.255.25542949672950xFFFFFFFF

Step-by-Step Conversion: 192.168.1.1

Octet 1:  192 x 256^3  =  192 x 16,777,216  =  3,221,225,472
Octet 2:  168 x 256^2  =  168 x     65,536  =     11,010,048
Octet 3:    1 x 256^1  =    1 x        256  =            256
Octet 4:    1 x 256^0  =    1 x          1  =              1
                                               ─────────────
Total:                                         3,232,235,777

Reverse Conversion: 167772161 to 10.0.0.1

167772161 / 16777216 = 10  remainder 1       β†’ Octet 1: 10
        1 /    65536 =  0  remainder 1       β†’ Octet 2: 0
        1 /      256 =  0  remainder 1       β†’ Octet 3: 0
        1 /        1 =  1                    β†’ Octet 4: 1
                                              β†’ Result: 10.0.0.1

When to Use the IPv4 Integer Converter

  • Database storage optimization -- store IP addresses as 4-byte integers (INT UNSIGNED in MySQL, integer in PostgreSQL) instead of 15-character strings, reducing storage by 70% and enabling indexed range queries
  • IP range lookups -- determine whether an address falls within a range using simple numeric comparison: ip_integer BETWEEN start_integer AND end_integer
  • Sequential address generation -- calculate the next or previous IP address by incrementing or decrementing the integer value
  • Sorting IP addresses -- sort addresses in correct numerical order by sorting their integer equivalents, avoiding lexicographic issues where 9.0.0.0 would sort after 10.0.0.0 with string sorting
  • GeoIP database queries -- many GeoIP databases store ranges as integer pairs for fast lookup performance
  • Network scanning tools -- enumerate all addresses in a range by iterating from the start integer to the end integer

How IPv4 to Integer Conversion Works

The 32-Bit Address Structure

An IPv4 address is fundamentally a 32-bit binary number. The dotted-decimal notation splits those 32 bits into four 8-bit octets for human readability. The integer form is simply the decimal value of those 32 bits read as a single number.

IPv4:      192    .   168    .     1    .     1
Binary:  11000000   10101000   00000001   00000001
32-bit:  11000000101010000000000100000001
Integer: 3,232,235,777

The General Formula

Integer = (Octet1 x 2^24) + (Octet2 x 2^16) + (Octet3 x 2^8) + Octet4

This is equivalent to (O1 << 24) | (O2 << 16) | (O3 << 8) | O4 using bitwise operations, which is how most programming languages implement the conversion internally.

Database Schema Example

-- MySQL: Store IPv4 as unsigned 32-bit integer
CREATE TABLE ip_allowlist (
    id INT AUTO_INCREMENT PRIMARY KEY,
    ip_address INT UNSIGNED NOT NULL,
    description VARCHAR(255),
    INDEX idx_ip (ip_address)
);

-- Insert 192.168.1.1
INSERT INTO ip_allowlist (ip_address, description)
VALUES (3232235777, 'Office gateway');

-- Query: Is 192.168.1.100 in the 192.168.1.0/24 range?
SELECT * FROM ip_allowlist
WHERE ip_address BETWEEN 3232235776 AND 3232236031;

Practical Advice for Integer IP Storage

When designing a database schema for IP addresses, the choice between integer and string storage depends on your query patterns. If you primarily look up individual addresses by exact match, string storage with an index works fine. But the moment you need range queries -- "find all addresses in this subnet" or "is this address in our allowlist range?" -- integer storage becomes dramatically faster and more correct. The performance difference is especially noticeable with GeoIP lookups, where you are searching through millions of ranges for every incoming request.

Be careful with signed versus unsigned integers. A 32-bit signed integer only goes up to 2,147,483,647, which corresponds to 127.255.255.255. Any address in the 128.0.0.0 through 255.255.255.255 range requires an unsigned integer. In MySQL, use INT UNSIGNED. In PostgreSQL, use bigint (since PostgreSQL does not have a native unsigned 32-bit type) or store as inet which handles this natively. Getting the signedness wrong causes silent data corruption for addresses above 127.255.255.255.

If you are working in JavaScript, be aware that bitwise operators treat numbers as signed 32-bit integers. The expression (192 << 24) produces a negative number because 192 sets the sign bit. Use the unsigned right shift trick -- (192 << 24) >>> 0 -- to convert back to unsigned, or avoid bitwise operators entirely and use multiplication: 192 * 16777216 + 168 * 65536 + 1 * 256 + 1. JavaScript's Number type can safely handle all IPv4 integers since the maximum (4,294,967,295) is well below the safe integer limit (2^53 - 1).

Frequently Asked Questions

Why not just store IP addresses as strings in the database?

String storage works but has drawbacks. A string like "192.168.1.1" uses 13 bytes versus 4 bytes for an integer. More importantly, string comparisons produce incorrect results for range queries -- the string "9.0.0.0" is greater than "10.0.0.0" lexicographically. Integer storage enables correct range comparisons with standard operators and is significantly faster for indexed lookups.

What is the valid integer range for IPv4 addresses?

The valid range is 0 (0.0.0.0) to 4294967295 (255.255.255.255). This is the full range of a 32-bit unsigned integer. Negative numbers and values exceeding 4294967295 are invalid and do not correspond to any IPv4 address.

How do I handle the integer in JavaScript?

JavaScript's Number type safely handles integers up to 2^53 - 1, which is far larger than the maximum IPv4 integer of 2^32 - 1. Standard arithmetic works correctly. However, be careful with bitwise operators in JavaScript, which treat numbers as signed 32-bit integers -- 192.168.1.1 would produce a negative result with (192 << 24). Use >>> 0 (unsigned right shift by zero) to convert back to unsigned.

Can I use this tool to calculate subnet ranges?

Yes. Convert the network address and broadcast address to integers, and the range between them (inclusive) represents all addresses in the subnet. For example, 192.168.1.0/24 has network integer 3232235776 and broadcast integer 3232236031, so the subnet contains integers 3232235776 through 3232236031 (256 addresses).

How does this relate to the inet_aton() function in MySQL?

MySQL's INET_ATON() function performs exactly this conversion: it takes a dotted-decimal IPv4 string and returns the unsigned 32-bit integer. INET_NTOA() does the reverse. This tool performs the same calculation, letting you verify conversions or compute values outside of a database context.

Related Tools

IPparseβ€’Free Network & Subnet Calculator Tools

Β© 2026 IPparse. All tools run locally in your browser.

100% Privacy-First β€’ No Data Collected