1. Home
  2. Developer tools
  3. IPv4 to Integer

IPv4 to Integer

Databases, firewalls and some APIs store an IPv4 address as one number so ranges can be compared and indexed. Paste addresses and get the integer for each.

Free, no sign-up. Runs in your browser: nothing is uploaded.

How to use IPv4 to Integer

  1. Paste IPv4 addresses, one per line.
  2. Read the integer for each line.
  3. Check the other forms of the first address below.

Features

  • Converts lists of addresses
  • Exact 32-bit arithmetic
  • Also shows hex, binary and octal forms
  • Rejects octets above 255 and leading zeros
  • Classifies the first address (private, loopback, public)
  • Copy or download the result

Supported formats

Input

  • IPv4 addresses
  • Typed or pasted text

You get

  • Decimal integer
  • Hex and binary forms

Private by design

Everything you enter is processed by your browser on this device. Nothing is sent to openWorkstand or anyone else, so the IPv4 to Integer is safe for private and work data. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • Only dotted-decimal IPv4 addresses are accepted; octal and hex octets are rejected rather than guessed.
  • The integer is the unsigned 32-bit value; signed 32-bit columns will show a negative number for addresses above 127.255.255.255.

Guide

Storing and comparing IPv4 addresses as single integers

An IPv4 address looks like four small numbers, but a computer sees one 32-bit value. Turning the dotted text into that single integer is a routine step when you store addresses in a database, build an allow list that works on ranges, or read a log that wrote the address as a bare number. The page converts a list of addresses, one per line, and shows every spelling of each so you can pick the one your system expects.

The calculation

Think of the four bytes as digits in base 256. The first byte is worth 256³ (16,777,216), the second 256² (65,536), the third 256 and the last 1. Multiply, add and you have the integer. Computers do the same with bit shifts: the first byte is shifted left by 24 places, the second by 16, the third by 8. Because the first byte has the greatest weight, comparing two integers gives the same order as comparing the addresses octet by octet. That is why BETWEEN queries on an integer column can answer “is this address in that range?” with a simple index lookup, something text columns cannot do.

What the page shows

Every address gets its decimal integer in the output box, one per line. A panel under it takes the first valid address and lists it as dotted decimal, 0x hexadecimal, dotted hexadecimal, dotted binary and dotted octal, plus the kind of address: private under RFC 1918, shared carrier-grade NAT space, loopback, link-local, documentation or ordinary public space. The list of results can be copied or downloaded as a text file, one number per line, which suits pasting into a spreadsheet or an import script.

Traps worth knowing

The value is unsigned and runs from 0 to 4,294,967,295. A signed 32-bit database column, such as a plain INT in MySQL or the integer type in PostgreSQL, tops out at 2,147,483,647, so any address above 127.255.255.255 overflows or turns negative. Store the number in an unsigned INT or a 64-bit column instead. Leading zeros are another source of confusion: some libraries read 010 as octal 8, so the page rejects such octets instead of guessing. Whitespace around an address is ignored, and a line that is not an IPv4 address produces a message that quotes the offending text rather than being silently skipped.

A worked example

Enter 192.168.1.1. The sum is 192 × 16,777,216 = 3,221,225,472, plus 168 × 65,536 = 11,010,048, plus 1 × 256 = 256, plus 1, which comes to 3,232,235,777. The hexadecimal form is 0xC0A80101, the dotted binary form is 11000000.10101000.00000001.00000001, and the page marks it as private use under RFC 1918. If a signed column stored it, the value would read back as 3,232,235,777 − 4,294,967,296 = −1,062,731,519, which is the classic symptom of the wrong column type.

Limits

Only IPv4 is supported; an IPv6 address needs 128 bits and does not fit any ordinary integer type, so databases store it as binary or as a dedicated type. The page converts text, it does not look up who owns an address or whether it is in use. If you need to go the other way, the Integer to IPv4 Converter does the reverse.

Checked against the current version of the IPv4 to Integer on .

Frequently asked questions

Why is 10.0.0.1 a smaller number than 192.168.1.1?

The first byte carries the most weight. 10 times 16,777,216 is far less than 192 times that, so addresses sort numerically in the same order as they do octet by octet, which is what makes range queries work.

Is the integer the same as the number that MySQL INET_ATON returns?

Yes. INET_ATON and this page both treat the four bytes as one big-endian unsigned number, so 192.168.1.1 gives 3232235777 in both.

What is 192.168.1.1 as an integer?

3,232,235,777. Each octet is multiplied by 256 to the power of its position from the right and the products are added.

Why store IP addresses as integers in a database?

Integers take 4 bytes, sort in numerical order and make range queries with BETWEEN fast. A subnet becomes a pair of integers.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.