Background: Primary headaches include migraines, tension-type headaches and other primary headache syndromes. Migraines and tension-type headaches are associated with patient discomfort and other diseases. This study aimed to investigate the association between primary headaches and the risk of developing dementia, and to clarify the association between different types of headaches and dementia. Materials and Methods: We conducted a nationwide matched cohort population-based study. A total of 3,620 patients with newly diagnosed primary headaches, including migraines and tension-type headaches, between January 1 and December 31, 2000 were selected from the National Health Insurance Research Database of Taiwan, along with 10,860 controls matched for sex and age. After adjusting for confounding factors, Fine and Gray's competing risk analysis was used to compare the risk of developing dementia during 10 years of follow-up. Resuls: Of the study subjects, 170 (4.70 %) developed dementia compared with 433 (3.99%) of the controls. Fine and Gray's competing risk analysis revealed that the study subjects were more likely to develop dementia (hazard ratio = 2.057; 95% CI: 1.718-2.462; P < 0.001). After adjusting for sex, age, monthly income, urbanization level, geographic region of residence and comorbidities, the hazard ratio for dementia was 2.048 (95% CI: 1.705-2.461, P < 0.001). Migraines and tension-type headaches were associated with nonvascular dementia but not vascular dementia. Conclusions: The patients with headaches had a 105% increased risk of dementia. Further studies are needed to elucidate the underlying mechanisms.