Among a variety of comorbidities of ankylosing spondylitis (AS), the association between dementia and AS by using an extensive dataset from the Korean National Health Insurance System was evaluated in this study. We extracted 15,547 newly diagnosed AS subjects among the entire Korean population and excluded wash-out patients (n = 162) and patients that were inappropriate for cohort match (n = 1192). Finally, 14,193 subjects were chosen as the AS group, and through 1:5 age- and sex-stratified matching, 70,965 subjects were chosen as the control group. We evaluated patient demographics, household incomes, and comorbidities, including hypertension, diabetes, and dyslipidemia. The prevalence of overall dementia (1.37%) and Alzheimer’s dementia (AD) (0.99%) in the AS group was significantly higher than in the control group (0.87% and 0.63%), respectively. The adjusted hazard ratio of the AS group for overall dementia (1.758) and AD (1.782) showed statistical significance also. On the other hand, the prevalence of vascular dementia did not differ significantly between the two groups. Subgroup analyses revealed the following risk factors for dementia in the AS group: male gender, greater than 65 years in age, fair income (household income greater than 20% of the median), urban residency, no diabetes, and no hypertension. From the nationwide, population-based, retrospective, longitudinal cohort study, AS patients showed a significantly higher prevalence of overall dementia and Alzheimer’s dementia. Comprehensive patient assessment using our subgroup analysis could help to prevent dementia in patients suffering from AS.