It's not a mystery, as is often said, but it's very complicated. And it's physical as well as mental. The two are totally intertwined and can't be separated.
Just saw "Big Mind." Truly weird video. I don't think you can expect this to happen in more than one in 100 million cases. But it does bring out several relevant points: this guy memorizes and calculates the same way we memorize and make calculations about a piece of music: via signposts--tangible, kinesthetic signposts. I'm not comparing myself to this guy in any way (what he does is totally miraculous), but I can say that my brain works the same way when dealing with music. Keys have definite colors for me.
Read the rest of How does the brain work?