Distinguishing between normal and pathological cognitive aging is challenging because there is no typical older person. Some people in their eighties have cognitive abilities similar to many 30-year-olds, while others experience significant cognitive decline at a much younger age. The variation in age-related cognitive decline is not arbitrary. Several non-modifiable (e.g. genetic) and potentially modifiable (e.g. high blood pressure, smoking, and hearing loss) risk factors are associated with faster cognitive aging. Beyond these individual-level risk factors, a growing body of evidence has identified associations between cognitive impairment and social, economic, and environmental factors. These associations are even more pronounced in developing countries, notably because of greater disparities in education and socioeconomic status. However, people from these countries are rarely studied in scientific research: a citizen of a high-income country is 37 times more likely to appear in a study in top medical journals than a citizen of a low-income country. Here, we examine the association between sociodemographic factors and cognitive aging trajectories among 715,295 participants in 46 countries. Cognition is assessed using Sea Hero Quest, a spatial navigation video game that predicts spatial ability in the real world. We find that the social, economic, and environmental well-being of older adults, as measured by the Global AgeWatch Index (GAWI), is negatively associated with age-related decline in spatial ability. In particular, the GAWI Health and Environment subscores are strongly correlated with the effect of age on wayfinding performance. We also found that gender differences in spatial navigation skills increase with age, and even more so in countries with greater gender inequality, as estimated by the Gender Inequality Index. Our results show that cognitive aging must be understood as a dynamic, heterogeneous process that is strongly linked to potentially modifiable environmental and social factors.