Public Transport in Madrid is organized very well. You can choose between the metro, train, bus, and taxi if you want to go somewhere.
They also have a bicycle renting system called BiciMAD. A subscription for this costs €25,- a year. For the first 30 minutes, you use the bicycle, you pay €0,50. For the next 30 minutes, you will pay €0,60. If you use the bicycle for more than 2 hours, you have to pay €4,- for every extra hour. You don’t have to get an abonnement for one year, you can also choose to just pay for one or two hours. The prices for one hour are €2,- and for two hours will be €4,-. If you are planning to use the bikes often, it is cheaper to go for an abonnement. More information can be found on the website of BiciMAD.
The bus runs from 6 am to 11.30 pm. Night Busses run from 11.20 pm or 11.45 pm to 5.30 am or 6 am and until 7 am on Saturday nights. If you want to go to another town in the region, you can take an intercity line.