Madrid is a very uncomfortable city for bikes. I don't know what will be the way you would do, but in general I would forget about the bike if you'll be only 5 weeks. Plus, in summer it's hot. The good thing it's than in August the streets are empty and the cars won't disturb you so much.
It's possible to get in with the bike in the train (cercanias) or metro in weekends and on some times. About bus between cities it depends on the company, you have to ask first.