Er, you can't do MAD-BCN-MAD if your originating city is Madrid. First time you return to your point of origin is the end of your trip. And bear in mind that you can only reenter the country of origin once (with some exceptions, but Spain isn't one of them).