(born in Barcelona, lived on both cities): these two are really different places. Tech scene is also clearly different. As I see it, Barcelona is smaller and cozier, tech scene might be hotter, but that might be from my own bias. Madrid is big, active and noisy. There are plenty of jobs on Madrid, compared to Barcelona, although I still think the hot stuff is on the latter.
Being both cities relatively near, why don't you take a week to visit them both? Register to some meetups, visit tech hubs, incubators, etc, and see for yourself which one feels like the place you want to be in. Now is a good time to visit, as the weather is calm. I would stay away from Madrid on august.
As for freelancing, I wouldn't recommend unless you are going to work for foreign clients.
Being both cities relatively near, why don't you take a week to visit them both? Register to some meetups, visit tech hubs, incubators, etc, and see for yourself which one feels like the place you want to be in. Now is a good time to visit, as the weather is calm. I would stay away from Madrid on august.
As for freelancing, I wouldn't recommend unless you are going to work for foreign clients.