Madrid nickname is “The European city of the night”. One of the advantages is that everybody can find an atmosphere at his taste. Nightlife in Madrid is often nomadic because Spanish people never stay in the same place all the night. They move from one bar to another in the same lively place.
The most popular places are in Alonso Martinez, Bilbao, Santa Ana, Huertas, Argüilles and Moncloa. Nightclubs and bars close very late in the night or very early in the morning, as you prefer ! In order to go back home, the underground close at 2 a,m, but it is early if you want to do party as a proper Spanish. A lot of buses run all the night and the principal lines work. You can also take the taxi. Everything depends on where you need to go, but if the taxi is full, the price for each person is not so expansive. At least, it will be always cheaper than taking a taxi in London !