Background: This empirical study aims to investigate the association between mathematics self-efficacy and mathematics achievement gaps among students in Grades 4, 8, and 12, utilizing data from the 2019 National Assessment of Educational Progress (NAEP). The study also considers student-level (e.g., mathematics self-efficacy, gender, race/ethnicity) and school-level (e.g., school location, proportion of underrepresented students) demographics to provide a comprehensive analysis of the factors contributing to mathematics achievement gaps. Methods: A two-level cross-sectional multilevel modeling approach was employed to analyze the variance in mathematics achievement, partitioning it into within- and between-school components. This approach allowed for an examination of association between mathematics self-efficacy and achievement gaps while considering various student and school characteristics. The rationale behind this methodology lies in its ability to capture the hierarchical nature of educational data and provide a nuanced understanding of the factors associated with mathematics achievement. Results: The analysis of the NAEP data revealed substantial variability in mathematics achievement across schools in the United States at all grade levels. Furthermore, mathematics self-efficacy emerged as a robust predictor of students' mathematics achievement, exhibiting significant effect sizes for Grades 4, 8, and 12. Remarkably, when students' mathematics self-efficacy was held constant, the mathematics achievement gaps among different student subgroups by gender, race/ethnicity, ELL, IEP, NSLP status narrowed, highlighting the importance of self-efficacy in addressing these disparities. The study also identified the presence of significant school contextual effects, further emphasizing the role of the educational environment in shaping mathematics achievement. Conclusions: This study underscores the critical role of mathematics self-efficacy in influencing mathematics achievement gaps among students. By acknowledging the association between self-efficacy beliefs and mathematics achievement, policymakers and educators can develop targeted interventions to enhance students' confidence and motivation in mathematics, ultimately promoting equitable educational outcomes. The findings also emphasize the significance of school-level factors, calling for comprehensive approaches that consider both individual and contextual factors in narrowing achievement gaps. The implications of adopting a self-efficacy perspective to address mathematics achievement gaps extend to educational policy, curriculum development, and instructional practices, ultimately fostering more inclusive and effective mathematics education for all students.