I have to create a field in a mysql table to store ip addresses. I need to know the maximum characters an ip address can possibly be. Whether ipv4, ipv6 or some other type that can render a valid ip address unusually long. So what should I set the character limit to?

I am asking for length in the sense that the word "foo" has 3 characters, not in terms of bytes or anything like that.

link|improve this question
feedback

1 Answer

up vote 6 down vote accepted

An IPv6 address, at its longest, would be 8 sets of 4 characters (32 total), each set separated by a colon. That makes 39 characters.

An IPv4 address is at most 4 sets of 3 numbers (12 characters), each set separated by a dot (.). That makes 15 characters.

All of this assumes the IP addresses should be stored in human-readable form. I prefer to store IP addresses in decimal form, as you never quite know how it will be used. Your mileage may vary.

link|improve this answer
Thanks a lot, human readable form is fine for my use case as I am never going to use them generally. I am only storing the ips of people who signup on my site in case they ever upload anything seriously offending and I have to hand over their info to authorities. – Lonand Jan 22 at 0:17
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.