Background: The relative impact of immune deficiency and lifestyle related factors on risk of cancer in the HIV infected population is controversial. We aimed to estimate the population attributable fractions (PAFs) of cancer associated with smoking, immune deficiency and with being HIV-infected. Methodology: In a Danish, nationwide, population-based cohort study, 1995-2011, incidences of cancer were compared between the HIV-infected population and a matched population-based cohort. Analyses were stratified on cancer category (smoking-related, virological or other), smoking status and nadir CD4/duration of CD4<200 cells/μL. We used Poisson regression to estimate incidence rate ratios (IRR). PAFs associated with HIV were calculated by comparing HIV-infected with HIV-uninfected non-smokers. Results: A total of 3,503 HIV patients and 12,979 population controls were followed for 18,679 and 55,957 person-years. HIV patients were on antiretroviral therapy during 92% of the observation time. Median CD4 at study inclusion was 450 cells/μL (IQR 310-630). Smoking-related and virological cancers accounted for 23% and 43% of cancers in the HIV-infected population (Figure 1). The IRR (95% CI) of smoking-related, virological and other cancers among HIV patients compared to controls were 2.8 (1.6-4.9), 11.5 (6.5-20.5) and 1.0 (0.7-1.3), respectively. Among non-smoking HIV patients compared to non-smoking controls there was increased risk of virogical cancer (17.0 (6.02-47.9)), but the risk of non-virological cancers was not elevated (1.2 (0.7-2.1)).The PAFs associated with being HIV infected were 56% for all cancers and 94% for virological cancers. The PAF associated with smoking was 27% for all cancers and 91% for smoking-related cancers. The risk of lung cancer was increased among HIV patients with nadir CD4 <200 cells/μL (IRR (95%CI) 3.54 (1.00-12.59)), but was not associated with duration of CD4 <200 cells/μL (1.07 per year (0.87-1.32)). For non-virological cancers that are not strongly related to smoking the PAF associated with immune deficiency was 0%. Conclusions: In a well-treated HIV infected population the risk of cancer is increased approximately two-fold compared to the background population. In absence of smoking the increase in risk is confined to virological cancers, whereas the risk of other cancers does not differ between HIV infected and uninfected individuals and does not seem to be associated with immune deficiency.