Depression is highly common throughout the life course and dementia is common in late life. Depression has been linked with dementia, and growing evidence implies that the timing of depression may be important in defining the nature of this association. In particular, earlier-life depression (or depressive symptoms) has consistently been associated with a more than twofold increase in dementia risk. By contrast, studies of late-life depression and dementia risk have been conflicting; most support an association, yet the nature of this association (for example, if depression is a prodrome or consequence of, or risk factor for dementia) remains unclear. The likely biological mechanisms linking depression to dementia include vascular disease, alterations in glucocorticoid steroid levels and hippocampal atrophy, increased deposition of amyloid-β plaques, inflammatory changes, and deficits of nerve growth factors. Treatment strategies for depression could interfere with these pathways and alter the risk of dementia. Given the projected increase in dementia incidence in the coming decades, understanding whether treatment for depression alone, or combined with other regimens, improves cognition is of critical importance. In this Review, we summarize and analyze current evidence linking late-life and earlier-life depression and dementia, and discuss the primary underlying mechanisms and implications for treatment.