I am checking my luggage thru to Barcelona. I change planes in Madrid. Will my luggage be offloaded in Madrid for customs?
I would not worry too much about the re-checking bags issue. Assuming Madrid is like most other International->Domestic transfers, your bags would be tagged all the way to BCN, but come out on the belt in Madrid for you to go through customs. You would just need to grab your bag, walk "across the line" through customs and immediately drop your bags to continue with you.
Other people asked questions on similar topics, check out the answers they received:
Other people asked questions on various topics, and are still waiting for answer. Would be great if you can take a sec and answer them