The cognitive-buffer hypothesis proposes that more harsh and unpredictable environments favour animals with larger brains and resulting greater cognitive skills. Comparisons across taxa have supported the hypothesis, but it has rarely been tested within a species. We measured brain size, as inferred from head dimensions, for 1141 cliff swallow specimens collected in western Nebraska, 1982-2018. Cliff swallows starving to death during unusual late-spring cold snaps had significantly smaller brains than those dying from other causes, suggesting that brain size in this species can affect foraging success and that greater cognitive ability may confer advantages when conditions exceed normal environmental extremes. Brain size declined significantly with the size of the breeding colony from which a specimen came. Larger brains may be favoured in smaller colonies that represent more unpredictable and more challenging social environments where there is less public information on food sources and less collective vigilance against predators, even in relatively normal conditions. Our results provide intraspecific support for the cognitive-buffer hypothesis and emphasize the potential evolutionary impact of rare climatic events.