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

2 Answers 2

up vote 8 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

If you include the slash notation, e.g.

then it can be up to 18 characters.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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