In Australia, hepatitis B (HBV) vaccination is recommended for injecting drug users (IDUs), Indigenous adults and prisoners. We compared immunity to HBV in prisoners and the general population obtained from national serosurveys in 2007. Individuals with HBV surface antibody (HBsAb) positive sera were considered immune from past infection [HBV core antibody (HBcAb) positive] or from vaccination (HBcAb negative). Male prisoners aged 18–58 years had a higher HBsAb seroprevalence than the general population (46·4% vs. 39·4%, P = 0·061). Comparison of HBcAb results was possible for males aged 18–29 years. In this group, higher HBsAb seroprevalence was due to past infection (12·9% vs. 3·0%, P < 0·001), rather than vaccine-conferred immunity (35·3% vs. 43·4%, P = 0·097). All prisoner groups, but especially IDUs, those of Indigenous heritage or those with a previous episode of imprisonment had higher levels of immunity from past infection than the general population (19·3%, 33·0%, 17·1%, respectively, vs. 3·0%, P < 0·05). Indigenous prisoners, non-IDUs and first-time entrants had significantly lower levels of vaccine-conferred immunity than the general population (26·4%, 26·2% and 20·7% respectively vs. 43·4%, P < 0·05). Improving prison-based HBV vaccination would prevent transmission in the prison setting and protect vulnerable members of the community who are at high risk of both infection and entering the prison system.