Well, with anything, practice is key. When I was in school, I was in a math competition where you had to do everything in your head. There was no scratch paper, you could not modify your answer once written, and erasing was obviously not allowed either. I wasn't the greatest at it, but I didn't suck at it either. That was decades ago, and I no longer do math in my head that way. What I used to do in seconds for a result now takes a couple of seconds to think about what needs to be done and then the time to come up with the result.