I've been going to Madrid for decades, and I recommend staying near the Puerta del Sol in the heart of the city.
After weeks of albergues, I don't mind staying in a hostel in Madrid. This last October I stayed in Toc Hostel Madrid (reservations on Booking.com), and I really liked the people in the dorm with me (one from Japan, one from Germany, one from the UK--all in the 20s), and me, from the US (in my 60s). The dorms are mixed (8 beds, I think, with a storage locker for each), and the showers are of the change-and-shower-in-the-same-space variety. Bed linens, a duvet, and towels are provided. There's a great kitchen, dining area and lounge with a pool table on an upper floor which all turned into a party zone on the night I was there. It's on Calle Arenal, a really wonderful pedestrian-only street, one that leads from the Puerta del Sol, a major shopping and entertainment area. The Plaza Mayor is a few blocks away in one direction, and the main drag, Gran Via, is a few blocks in another. Chueca, a really cool neighborhood, is just beyond that. I would have stayed a second night, but they were full, so I had to move to another, much less desirable place in a much less desirable location (only advantage was that it was closer to the airport on the metro).
To get to the airport, I take the metro. As of now, it costs €1.50 for the fare and €2.50 for the "Tarjeta Multi," the card used to load metro and the local train ("Cercanias") fares on (which you can keep and reuse on your next camino; it is valid for 10 years), and €3 airport supplement, so, if you use the metro only to get to the airport, you'll pay €7. There are stops at all the terminals, but in between them, there is a stop for "Barajas," but it's the town, not the airport. I think I had to transfer from the red line (Puerta del Sol station) to the gray line, maybe, (lines are indicated by color and number), but it's pretty uncomplicated if you've used subways before.
[Note or aside: If you arrive at Madrid Barajas and plan to take the train to Pamplona, get your ticket at the Renfe office in Terminal 4. The fare gets you all the way from the airport to Pamplona; you don't have to find your own way on the metro or a bus to the train station if you buy your ticket at the airport.]
Note that the metro is a great way to get around Madrid; the maps are easy to follow if you've ever used a subway. It seems to me that announcements are also in English now as well. You can also get to nearby towns on the Cercanias-local trains, and they're cheap; load the fare on the TarjetaMulti.