See also: 100 Things to Do in Madrid
Madrid's sex district is little more than a large number of sex shops, invariably with 'cabins' to watch pornography and some with peep shows. A few also offer contact with the 'models'.
The biggest such sex shops are on c/Atocha, the street that connects the main Atocha train station with the center. One of them also has a museum of erotic art.
The other main areas where you will find such shops are on c/Montera (between Puerta del Sol and Gran Via) and in the streets immediately north of Gran Via. There is even a sex shop on Gran Via itself.
The only area I would recommend keeping away from (at night, at least) is c/Luna, a large plaza/street just north of Gran Via. The streets around here have a number of sex shops and at night attract prostitutes, but in the day time there are restaurants and people around, making it a safe place to be.
Prostitutes congregate around this area north of Gran Via, as well as on the aforementioned c/Montera. They are known to hassle men, making distinctly unattractive clucking noises (I've no idea on what planet that is considered sexy) and at times grabbing hold of men. Montera at night is when there are the most prostitutes on the streets and so is probably best avoided, however, apart from the fact that it is aesthetically displeasing, trouble rarely occurs. Women in particular, as long as they keep walking, should not have anything to fear - it is obvious which girls are the prostitutes, so neither the sex workers nor their clients are likely to pay you any attention. Men should be more wary, as the amorous attention that the girls 'lavish' on you is often accompanied with stray hands that might find their way onto your wallet.