To evaluate the prognostic and molecular mechanisms of sex and racial differences in gastric cancer, data from two large centers were used to retrospectively analyze the survival of gastric cancer patients with regard to sex and racial differences. In examining the molecular mechanism of sex in gastric cancer patients of different races, data from The Cancer Genome Atlas database were used to analyze differentially expressed genes (DEGs), and Gene Ontology (GO) enrichment and DNA methylation analyses were performed. Among White gastric cancer patients, it was found that the survival prognosis for females was better than that for males; conversely, among Chinese patients, males had a better prognosis. For African Americans, sex may have an impact on gastric cancer, but this relationship was unclear. The core DEGs between the different sexes included glycogenin 2 pseudogene 1, ribosomal protein S4 Y‑linked 1, taxilin‑γ and eukaryotic translation initiation factor 1A X‑linked among White patients, and GO enrichment analysis revealed that these genes act mainly through RNA binding and transcription pathways. Among Black patients, core DEGs included DnaJ heat shock protein family (Hsp40) member C5, histone deacetylase 10, neogenin 1 and SMG5 nonsense mediated mRNA decay factor, which are mainly related to pathways of cellular structural changes based on GO enrichment analysis. For Asian patients, core DEGs included zinc finger protein Y‑linked, thymosin β4 Y‑linked, zinc finger protein 787 and ubiquitously transcribed tetratricopeptide repeat containing, Y‑linked, participating in cell surface receptor‑associated signal transduction and G‑protein coupled receptor protein signaling pathways, according to GO. The expression of different core genes and differences in pathways are likely to be the main causes affecting the variation observed among gastric cancer patients of different races and sexes.