In recent years, as the shrimp farming industry has experienced a range of environmental challenges, astaxanthin (AST) has attracted significant interest as a potential feed composition that could improve both the health and output of shrimp. Yet, the molecular process is still unclear. In this study, astaxanthin's effects both in vivo and in vitro on the intestinal microbiota and gene expression in pacific white shrimp (Litopenaeus vannamei) were researched. For the in vitro culture, the result showed that the intestinal microbiota was no significant difference. There were 255 genes up-regulated and 670 genes down-regulated in differentially expressed genes (DEGs). Linear discriminant analysis (LDA) effect size (LEfSe) analysis for the in vivo trial revealed that Donghicola, Xanthomarina, Cellulophaga, Pirellula, and Neptunomonas reduced while Leuconostoc considerably increased after astaxanthin intervention (LDA score >2). In vivo, there were 435 genes up-regulated and 249 genes down-regulated among DEGs, indicating that astaxanthin was involved in the differential pathway, which included various types of N-glycan biosynthesis, glycosphingolipid biosynthesis, ascorbate and aldarate, etc. The study provided theoretical support for astaxanthin in aquaculture and food applications.