This illusion occurs because the visual areas of the occiptal lobe are topographically organised: the pattern you see is laid out and recognised spatially, allowing the brain to see the edges of an object. We see overall patterns, not actually the lines and dots present in anything, just the whole image. When the edges are undefinable as in this case, the brain groups all the lines it sees together (grouping makes it easier for the brain to identify what it sees and simplify the interpretation process), thus it appears the elephant has more legs than it does. The brain has been tricked into grouping the lines in a way it is not used to.
(You can boo me now

)