Previous studies have shown that Ogt-mediated O-GlcNAcylation is essential for neuronal development and function. However, the function of O-GlcNAc transferase (Ogt) and O-GlcNAcylation in astrocytes remains largely unknown. Here we show thatOgtdeficiency induces inflammatory activation of astrocytes in vivo and in vitro, and impairs cognitive function of mice. The restoration of O-GlcNAcylation via GlcNAc supplementation inhibits the activation of astrocytes, inflammation and improves the impaired cognitive function ofOgtdeficient mice.Mechanistically, Ogt interacts with NF-κB p65 and catalyzes the O-GlcNAcylation of NF-κB p65 in astrocytes.Ogtdeficiency induces the activation of NF-κB signaling pathway by promoting Gsk3β binding. Moreover,Ogtdepletion induces the activation of astrocytes derived from human induced pluripotent stem cells. The restoration of O-GlcNAcylation inhibits the activation of astrocytes, inflammation and reduces Aβ plaque of AD mice in vitro and in vivo.Collectively, our study reveals a critical function of Ogt-mediated O-GlcNAcylation in astrocytes through regulating NF-κB signaling pathway.Supplementary InformationThe online version contains supplementary material available at 10.1186/s12974-023-02824-8.