Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
Please move to stackoverflow.com: it is a programming question –  djechelon Nov 7 '14 at 14:46

1 Answer 1

up vote 10 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.

share|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 '12 at 0:17

protected by Community Nov 8 '14 at 5:02

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

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