Well as MM knows my appartment in Barrio Salamanca was expensive . It´s a top floor (6th) apartment , very light , incredible views and 2 bedrooms . Not very big . It also had it's own underground parking space ( though I don't drive ) .. That cost €1,300 per month ! I lived there for about 3 years alone and then found a Spanish flatmate for a year or so and then a Peruvian flatmate for some time before I eventually left Madrid . The last year or so I had the rent reduced to €1,000 .
I would say ( sorry ) that there is no chance you'll get a city apartment , even a studio , for €400 ... Most people do choose to share an apartment . I was always used to having my own space so getting a room mate was a big change for me , but it worked out fine .
I got my apartment through segundamano.com .
Bear in mind that many Spanish landlords will give you just a 1 month contract and after that you will have just a contract of trust ( verbal ) and will pay in cash . This is so they can avoid the taxes . However if you are working legally in Spain you'll have to have a contract to claim back tax relief from the State .
Also , as has been mentioned in another thread . Having a contract is often necessary to gain your residency papers unless you have someone on the "inside" to help .
Getting back to the main point .. most of my Spanish and Latino friends were paying between €300-€500 for a room in a shared apartment .
And as MM has mentioned there are possibilities further out . A Spanish friend of mine rented a very nice , small , 2 floor , 1 bedroomed apartment in San Lorenzo el Escorial .. beautiful , historic town in the mountains . That cost him €450 a month .. Then , as MM pointed out you'd have to consider the commute into Madrid and the daily cost involved .
Anyway . Good luck wherever you end up .