Heart failure (HF) and atrial fibrillation (AF) often coexist. We explored AF incidence, prevalence, and treatment strategies in patients with versus without HF across the ejection fraction (EF) spectrum. We analysed patients with HF from the Swedish HF Registry (1 December 2005-31 December 2021), matched 1:1 by sex, age, and county of residence to patients without HF from Statistics Sweden. Two study cohorts were derived (i) to assess AF prevalence and treatments, and (ii) to evaluate AF incidence and related predictors. Overall, 195 106 patients were considered, 50% of them with HF (of whom 54% with HF with reduced [HFrEF], 23% mildly reduced [HFmrEF], and 23% with preserved EF [HFpEF]). From 2006 to 2021, AF prevalence increased in both patients with (57% to 58%) and without HF (8% to 11%). HF patients, particularly if with HFrEF, were more likely receiving AF treatments than those without HF. Over time, antiarrhythmic use decreased, while rate control drugs and oral anticoagulant use, and AF-related procedures increased, regardless of HF and EF. During a median follow-up of 3.7 years, in 86 210 patients without AF, incident AF risk was two-fold higher in HF versus non-HF (hazard ratio [HR] 2.76, 95% confidence interval [CI] 2.45-3.12), highest in HFpEF (HR 3.12, 95% CI 2.65-3.67) versus HFrEF (HR 2.68, 95% CI 2.34-3.06) and HFmrEF (HR 2.53, 95% CI 2.17-2.94). Atrial fibrillation prevalence, anticoagulant use, and AF-related procedures increased over time regardless of HF, with HF patients more likely receiving AF treatments. In HF, despite higher AF prevalence and incidence in HFpEF, AF treatment use remained modest, calling for further implementation.