Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 343477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:54:04+00:00 2026-05-12T10:54:04+00:00

I need to store IP address in the most compact way possible, searching is

  • 0

I need to store IP address in the most compact way possible, searching is not a concern. This also needs to be compatible on Windows, Linux, and Mac using any DB (MySQL, SQLite, Postgres, etc).

Thanks to the ip2long() and long2ip() functions in PHP I can convert a IP4 address to a small int field rather than a varchar(15) or whatever. The problem is that we are in a transition stage to IP6 which means that most of the existing best-practices are failing – including those functions which don’t work with IP6. Further more, DB specific functions like INET_ATON() and INET_NTOA() aren’t options here.

So how do you store IP address as INT’s (or any other compact format) in a way that will work on any system?

EDIT:
The thread Wrang-wrang pointed mentions the use of inet_ntop() and inet_ptop() to pack and unpack either IP4 or IP6. The problem is that they only work on Linux/Mac with PHP +5.1 (which isn’t a too big of a problem) and on windows with +5.3 (which is).

If that was not a problem are their replacements for the varbinary(16) field that was recommended in each database?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:54:04+00:00Added an answer on May 12, 2026 at 10:54 am

    You just need to choose a way of storing 128 bits:

    ::/96 — This is a 96-bit zero-value
    prefix originally known as
    IPv4-compatible addresses. This class
    of addresses were used to represent
    IPv4 addresses within an IPv6
    transition technology. Such an IPv6
    address has its first 96 bits set to
    zero, while its last 32 bits are the
    IPv4 address that is represented. The
    Internet Engineering Task Force (IETF)
    has deprecated the use of
    IPv4-compatible addresses with
    publication RFC 4291. The only
    remaining use of this address format
    is to represent an IPv4 address in a
    table or database with fixed size
    members that must also be able to
    store an IPv6 address.

    (from http://en.wikipedia.org/wiki/IPv6)

    I think two BIGINT UNSIGNED would be a reasonable way to store them, but I guess you could use a binary (byte array).

    This question appears to have been answered already at Working with IPv6 Addresses in PHP and How to store IPv6-compatible address in a relational database

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store a record for a user per IP address to limit
I need to store an IP address with a wildcard in it, like 10.0.%.1.
I'm working on an Address Book application in C++. I need to store the
I need to store email address from a simple form (like a newsletter), but
I need to store the IP address of the users who comment, in the
I need store just 10 arrays in my app, which I can change from
I have id values for products that I need store. Right now they are
I need to store a very large amount of instances of my class, and
I need to store a login session when the user is login and remove
I need to store GPS coordinates in a database. I've heard that floats are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.