Globally, the prevalence of tuberculosis (TB) disease is higher in males. This study examined the effect of sex and age on Mycobacterium tuberculosis (Mtb) infection. Demographic and exposure data were collected on household contacts of sputum smear-positive pulmonary TB patients in Brazil. Contacts with tuberculin skin test induration ⩾10 mm at baseline or 12 weeks were considered Mtb infected. The study enrolled 917 household contacts from 160 households; 508 (55.4%) were female, median age was 21.0 years (range 0.30–87.0) and 609 (66.4%) had Mtb infection. The proportion infected increased with age from 63.3% in girls <5 years to 75.4% in women ⩾40 years and from 44.9% in boys <5 years to 73.6% in men ⩾40 years. Multivariable modelling showed the odds of infection increased between age 5 and 14 years among female contacts (OR 1.5 per 5-year age increase; 95% CI 1.1–2.2; P = 0.02) and between ages 0–4 and 15–39 years among male contacts (OR 2.7, 95% CI 0.83–8.9 and 1.1, 95% CI 0.99–1.3 per 5-year age increase; P = 0.10, 0.07, respectively). The study suggests that the age at which Mtb infection increases most is different in females compared with males. Studies are needed to explore whether these findings are due to differences in host susceptibility, exposure outside the household or other factors.