In my case the problem was the same and happened after downgrading from the really slow lollipop to kitkat and rooting again. Formatting or factory reset did not help.
The solution was to boot into recovery (TWRP) after flashing a ROM and rooting, and there change the file system type. For example I switched from the recognized 8GB ext4 to FAT (this switched the capacity to 32GB) and then back again to ext4. This obviously deletes all apps & data.
Model: Nexus 7 (2012) WiFi, TWRP version 18.104.22.168
On the TWRP home, choose the option "Wipe", then "Advanced Wipe". Now from the available partitions select only Data and tap "Repair or Change File System". The next screen shows the current file system info, where you can tap "Change File System", then choose the desired one and swipe to apply this change. According to my previous instructions you may repeat this procedure twice, once to switch to FAT, then again to ext4.