From: http://dev.mysql.com/doc/refman/5.7/en/bit-functions.html#c9386
Posted by Neil Davis on April 3, 2008
Revised by Phillip Temple on September 11, 2008
If you store your ip addresses as a 32 bit unsigned integer representation instead of strings(using INET_ATON()), you can use bitwise operators to pull the octets for grouping and sorting when you need to retrieve them:
select
ipAddress, (ipAddress >> 24) as firstOctet,