To identify the sociodemographic factors associated to self-medication (i.e. use of non-prescription medicines) and undesirable self-medication, a cross-sectional study was carried out using a sample (n = 20,311) representative of the population of adults of 16 years of age and older in Spain. Multivariate Cox's regression was used. The prevalence of self-medication in the sample was 12.7% during the two weeks preceding the interview. Self-medication is more prevalent among women, persons who live alone, and persons who live in large cities. For persons who reported acute disorders, self-medication prevalence was higher among those with higher educational levels. The prevalence of undesirable self-medication in the sample was 2.5% during the two weeks previous to the interview. Undesirable self-medication is twice as common among persons older than 40 years, as compared to persons younger than 27 years. Undesirable self-medication prevalence is 53.0% higher among those who live alone as compared to those who live with their partner (95% confidence interval (CI): 15.2-103.2) and 36.8% higher among students as compared to full-time workers (95% CI: 1.9-83.5). People over 40 years of age, people living alone, and students should be the priority target populations for public health education programs aimed at improving the quality of self-medication behavior.