Brothels have been illegal since 1956, but the vast majority of brothels are loosely disguised as whiskerías or 'clubs' and are left to function as normal.
Prostitutes have been able to practice their trade freely and advertise frequently in the 'Relax' section of the classifieds in newspapers and magazines written in thinly veiled sexual jargon. However, a proposal in July 2011 suggested that all contact sections of newspapers should be closed down to prevent the advertising of prostitution. Read more here: Spanish Government to ban contact ads
What is illegal is street prostitution. Both prostitutes and their clients can be prosecuted in some parts of Spain, including Barcelona. Read more: Barcelona Crime: Fines for Prostitutes and Clients.
Prostitution in Spain doesn't have the stigma that it has in other countries. According to another Expatica.com article for the Spanish, going with a prostitute "damages a marriage far less than an affair." In a recent survey, it was found that one in four Spanish men has paid for sex.
However, prostitution in Spain is not the regulated wholesome affair that it is in, say, Holland and prostitutes in Spain should be avoided. Many double up as pickpockets, especially in busy areas like Gran Via in Madrid and Las Ramblas in Barcelona. So keep well away.
See also Is Nudism Legal in Spain?