The prison setting presents not only challenges, but also opportunities, for the prevention and treatment of HIV, viral hepatitis, and tuberculosis. We did a comprehensive literature search of data published between 2005 and 2015 to understand the global epidemiology of HIV, hepatitis C virus (HCV), hepatitis B virus (HBV), and tuberculosis in prisoners. We further modelled the contribution of imprisonment and the potential impact of prevention interventions on HIV transmission in this population. Of the estimated 10·2 million people incarcerated worldwide on any given day in 2014, we estimated that 3·8% have HIV (389 000 living with HIV), 15·1% have HCV (1 546 500), 4·8% have chronic HBV (491 500), and 2·8% have active tuberculosis (286 000). The few studies on incidence suggest that intraprison transmission is generally low, except for large-scale outbreaks. Our model indicates that decreasing the incarceration rate in people who inject drugs and providing opioid agonist therapy could reduce the burden of HIV in this population. The prevalence of HIV, HCV, HBV, and tuberculosis is higher in prison populations than in the general population, mainly because of the criminalisation of drug use and the detention of people who use drugs. The most effective way of controlling these infections in prisoners and the broader community is to reduce the incarceration of people who inject drugs.