Hepatocellular carcinoma (HCC) is a tumor with high morbidity and mortality. Current research suggests that statins may aid in its prevention and treatment, while studies on the associated mechanisms remain limited. Therefore, we aim to reveal the mechanism of atorvastatin treatment for HCC by using network pharmacology and bioinformatics methods. The databases SwissTargetPrediction, PharmMapper, and DrugBank were utilized to obtain targets of atorvastatin, while GSE169289, GSE135631, and GSE207435 were used to identify differentially expressed genes (DEGs) for HCC. The overlap between the two groups was used to identify atorvastatin's target for treating HCC. Following protein-protein interaction (PPI) analysis, hub genes were identified using Cytoscape software and LASSO analysis. The hub genes were further validated using data from The Cancer Genome Atlas (TCGA) and The Human Protein Atlas (HPA) databases. To evaluate the clinical significance of the hub genes, Kaplan-Meier (KM) survival analysis and Cox analysis were conducted. Kyoto Encyclopedia of Genes and Genomes (KEGG) and Gene Set Enrichment Analysis (GSEA) were performed to investigate potential mechanisms. Finally, molecular docking analysis was performed to validate the interaction between atorvastatin and the hub genes. A total of 1948 DEGs of HCC and 380 targets of atorvastatin were identified, respectively. After taking the intersection, 79 genes were identified as potential targets of atorvastatin for HCC treatment. After multiple screening methods, CYP2C9 was ultimately identified as the hub gene. Analysis of data from TCGA and HPA databases showed reduced expression of CYP2C9 in HCC tissues. KM and Cox analysis showed a favorable prognosis for HCC patients with high CYP2C9 expression. KEGG and GSEA indicated that metabolism of xenobiotics by cytochrome P450, and PPAR signaling pathway could be the potential mechanisms for atorvastatin in treating HCC. Molecular docking analysis revealed that atorvastatin binds to CYP2C9 with a binding energy of - 8.837, indicating highly stable binding. CYP2C9 is associated with the prognosis of HCC patients and could serve as a potential target for atorvastatin treatment in HCC.