Purpose The Prevalhep study seeks to determine the prevalence of factors associated with the hepatitis C (HCV) and B (HBV) virus in Spanish prisoners. Methods This was an observational, cross-sectional study which randomly selected 18 Spanish prisons to participate, with 21 prisoners per centre. Results There were 378 prisoners selected, 370 of whom had serological HCV and 342 had HBV data. The HCV population was predominantly male (91.6%), middle age (66.7% ≤ 40 years of age), of Spanish origin (60.5%), with a history of injection drug use (IDU; 23.2%), in prison <5 years (71.2%) and having entered prison after 2006 (51.9%). The prevalence of HCV was 22.7% (n = 84; 95% CI, 18.3-27.1) and HBV was 2.6% (n = 9; 95% CI, 0.2-4.9%). Of the patients with HCV, 40.5% were co-infected with HIV, 0.3% co-infected with HBV, and 1.5% with triple virus co-infection (HBV + HCV + HIV). The three markers of HB had been measured in 99 inmates: 32.1% had post-vaccination immunity (antiHBS+) and 30.4% contact status with HBV (HBcAb + and/or HBsAg+), while 37.5% were susceptible to HB. Conclusions The prevalence of HBV and HCV has decreased in the Spanish prison population, probably as a result of decrease in IDU transmission, and an increase in immigrant prisoner population that does not have this risk behaviour.