Ischemic stroke (IS) is a group of vascular disease concomitant with high morbidity and mortality. Berberine is a bioactive substance and it has known to improve stroke, but the mechanism is yet to be proven. Mice were fed with BBR for 14 days. Then, mice were made into MCAO/R models. Neurological score, infarct volume, neuronal damage and markers associated with inflammation were detected. We tested the changes of intestinal flora in model mice after BBR administration by 16SrRNA sequencing. Chromatography-mass spectrometry was used to detect butyrate chemically. Tissue immunofluorescence was used to detect the changes of microglia and astroglia in mice brain. Our findings suggest that berberine improves stroke outcomes by modulating gut microbiota. Specifically, after MCAO/R mice were given berberine, beneficial bacteria producing butyric acid increased significantly, and the mice also had significantly higher levels of butyric acid. Administration of butyric acid and an inhibitor of butyric acid synthesis, heptyl-coA, showed that butyric acid improved stroke outcomes in model mice. In addition, butyric acid could inhibit the activation of microglia and astrocytes in the brain of model mice, thereby inhibiting the release of inflammatory cytokines IL-6, IL-1β, TNF-α and improving stroke outcomes. Our results suggest that berberine may improve stroke outcomes by modulating the gut flora to increase the abundance of butyric acid. These findings elucidate the mechanisms by which berberine improves stroke outcomes and provide some basis for clinical treatment.