So how many characters is enough to store an ip address in a mysql table? As the length of IP address varies from IPv4 to IPv6, To define the size of a column that ip address is going occupy, we must know maximum length of the ip address in both versions so that we can assign the maximum length to mysql column.

IPv4 addresses will be similar to the one given below,

From the above sample we can identify IPv4 addresses will consists 4 sets of 3 numbers, each set is separated by a dot(.). So this makes the length to be 15 characters (12+3).

IPv6 addresses will be similar to this one,

IPv6 addresses will consists of 8 sets of 4 characters, each separated by a colon(:). So this makes the length to be 39 characters(32+7).

As IPv6 holds more number of characters(39), To store an ipaddress we need to have a column that holds 39 characters which is the maximum length of an ip address.


Comments (1)
  1. Image
    Andrei - Reply

    October 07, 2019

    An IPv6 address can also be under this form: 0000:0000:0000::0000:ffff: (IPv4 as the last two parts of an IPv6)

Leave a Comment

loader Posting your comment...