IP to Long Converter

Converts an IPv4 address like 192.0.2.1 into the single unsigned 32-bit integer ('long') that databases and firewall rules often use to store IP addresses as a sortable, indexable number. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-25

Overview

Introduction

Databases, firewall rules, and geolocation lookups frequently need to store or compare IP addresses as plain numbers rather than as dotted-quad text.

This tool converts an IPv4 address into that unsigned 32-bit integer form entirely in your browser, so nothing you paste is sent to a server.

What Is IP to Long Converter?

A converter that treats a dotted-quad IPv4 address as a single 32-bit unsigned integer, the same representation used internally by operating systems, routers, and many database schemas.

It's part of this site's Network Tools collection and runs entirely client-side.

How IP to Long Converter Works

Each of the four octets is validated as a number from 0 to 255, then combined using base-256 place values: octet1×16777216 + octet2×65536 + octet3×256 + octet4.

The result is a single integer between 0 and 4294967295 (2³²−1), the full range of a 32-bit unsigned value.

When To Use IP to Long Converter

Use it when a database column, API, or config file expects an IP address as an integer instead of a string.

It's also useful for sanity-checking a range query, like confirming that a given IP's integer value falls between two bounds in a CIDR block.

Often used alongside Long to IP Converter.

Features

Advantages

  • Instant, exact conversion with no rounding or precision loss.
  • Validates the input strictly, rejecting out-of-range octets and ambiguous leading zeros.

Limitations

  • IPv4 only — a 32-bit integer can't represent an IPv6 address.
  • Doesn't validate whether the address is publicly routable or reserved for private use.

Examples

Converting a documentation address

Input

192.0.2.1

Output

3221225985

192×16777216 + 0×65536 + 2×256 + 1 = 3221225985.

Converting the all-zeros address

Input

0.0.0.0

Output

0

Every octet is zero, so the resulting integer is 0.

Best Practices & Notes

Best Practices

  • Use the Long to IP Converter to check the round trip when debugging a stored value.
  • Store the integer as an unsigned 32-bit or a signed 64-bit column; a signed 32-bit column overflows for addresses above 127.255.255.255.
  • Document which byte order (network byte order, i.e. big-endian) the integer assumes if it's shared across systems written in different languages.

Developer Notes

The implementation uses plain multiplication rather than bitwise left-shift operators, since JavaScript's << operates on signed 32-bit integers and would produce a negative number for any address at or above 128.0.0.0.

IP to Long Converter Use Cases

  • Storing IP addresses in a database as a sortable, indexable integer column
  • Checking whether an address falls within a numeric IP range used by a firewall or geolocation table
  • Converting between the integer format used by legacy systems and dotted-quad notation

Common Mistakes

  • Using a signed 32-bit integer column, which overflows for any address at or above 128.0.0.0.
  • Assuming this works for IPv6 addresses, which need 128 bits, not 32.

Tips

  • Pair this with the Long to IP Converter to confirm a round trip when verifying stored data.

References

Frequently Asked Questions