Assuming textual representation in a string :
- 15 characters for IPv4 (
xxx.xxx.xxx.xxxformat, 12+3
separators) - 45 characters for IPv6
Those are the maximum length of the string.
Alternatives to storing as string:
- IPv4 is 32-bits, so a MySQL data type that can hold 4 bytes will do, using
INT UNSIGNEDis common along withINET_ATONandINET_NTOAto handle the conversion from address to number, and from number to address
SELECT INET_ATON('209.207.224.40'); -> 3520061480 SELECT INET_NTOA(3520061480); -> '209.207.224.40'
- For IPv6, unfortunately MySQL does not have a data type that is 16 bytes, however one can put the IPv6 into a canonical form, then separate them into 2
BIGINT(8 bytes), this however will use two fields.