Exposure to extreme cold or heat temperature is one leading cause of weather-associated mortality and morbidity in animals. Emerging studies demonstrate that the microbiota residing in guts act as an integral factor required to modulate host tolerance to cold or heat exposure, but common and unique patterns of animal-temperature associations between cold and heat have not been simultaneously examined. Therefore, we attempted to investigate the roles of gut microbiota in modulating tolerance to cold or heat exposure in mice. The results showed that both cold and heat acutely change the body temperature of mice, but mice efficiently maintain their body temperature at conditions of chronic extreme temperatures. Mice adapt to extreme temperatures by adjusting body weight gain, food intake and energy harvest. Fascinatingly, 16 S rRNA sequencing shows that extreme temperatures result in a differential shift in the gut microbiota. Moreover, transplantation of the extreme-temperature microbiota is sufficient to enhance host tolerance to cold and heat, respectively. Metagenomic sequencing shows that the microbiota assists their hosts in resisting extreme temperatures through regulating the host insulin pathway. Our findings highlight that the microbiota is a key factor orchestrating the overall energy homeostasis under extreme temperatures, providing an insight into the interaction and coevolution of hosts and gut microbiota.