Consumption of illegal drugs is a public health problem in Mexico, and the prison population is a vulnerable group with higher rates of prevalence than in the general population. The objective of this study was to determine the main socioeconomic variables associated with drug consumption in the prison population. Utilizing data from the Second Incarcerated Population Survey carried out by the Centre of Research and Teaching of Economics (CIDE) in Mexico, a logistic model in two stages was developed. The first stage analyzed the determinants of habitual drug consumption by prisoners (prior to admittance into prisons), while the second stage of the model addressed drug consumption within prisons. Prevalence of drug consumption previous to incarceration was 28.5%, although once people were imprisoned this figure dropped to 7.4%. The characteristics that most heavily influenced against the possibility of habitual drug consumption prior to admittance to prison were: preparatory school or higher, being employed and having children; while the variables associated negatively were: male gender, childhood home shared with adults who consumed illegal drugs; abandoning childhood home; and having previous prison sentences. Once in prison, the negative conditions in there are associated with drug consumption. Work and study during incarceration, in addition to being instruments for rehabilitation, seem to exert an important positive association against drug consumption. However, this correlation seems to be minimized in the face of negative conditions of the penal institution; thus, public policies are necessary to improve the prisoner's environment.