Maximizing the flow of students through the science, technology, engineering, and math (STEM) pipeline is important to promoting human capital development and reducing economic inequality 1 . A critical juncture in the STEM pipeline is the highly-cumulative sequence of secondary school math courses 2-5 . Students from disadvantaged schools are less likely to complete advanced math courses, but debate continues about why 6,7 . Here, we address this question using student polygenic scores, which are DNA-based indicators of propensity to succeed in education 8 . We integrated genetic and official school transcript data from over 3,000 European-ancestry students from U.S. high schools. We used polygenic scores as a molecular tracer to understand how the flow of students through the high school math pipeline differs in socioeconomically advantaged versus disadvantaged schools.Students with higher education polygenic scores were tracked to more advanced math already at the beginning of high school and persisted in math for more years. Molecular tracer analyses revealed that the dynamics of the math pipeline differed by school advantage.Compared to disadvantaged schools, advantaged schools tracked more students with high polygenic scores into advanced math classes at the start of high school, and they buffered students with low polygenic scores from dropping out of math. Across all schools, even students with exceptional polygenic scores (top 2%) were unlikely to take the most advanced math classes, suggesting substantial room for improvement in the development of potential STEM talent. These results link new molecular genetic discoveries to a common target of educational-policy reforms. Math matters for economic success. American students who take math courses beyond Algebra 2 are more likely to enroll in college, complete a STEM degree 2-4 , and have better labor market outcomes 5,9,10 . Students from low-income families and schools are unlikely to take advanced math courses in secondary school, which impairs their entry to post-secondary STEM