Racial and sex disparities are prevalent in surgical trainees. Although retrospective studies on resident attrition have been conducted for individual specialties, this study analyzes racial and sex differences in resident attrition among all surgical subspecialties over an 18-year period. To evaluate the racial and sex differences in resident attrition among surgical specialties over an 18-year period. This was a large, cross-sectional, database study that analyzed program-reported resident censuses (program information, resident demographics, and attrition status) obtained by the Association of American Medical Colleges from 2001 to 2018 for trainees in surgical residency programs. Data were analyzed from March 20, 2021, to June 8, 2022. Demographic trends (including race and ethnicity and sex) for all surgical subspecialty training programs over an 18-year period. Resident attrition includes all-cause withdrawals, dismissals, and transfers to another specialty. Unintended attrition encompasses all withdrawals, dismissals, and transfers except for changing career plans. This study included 407 461 program-reported resident years collected from 112 205 individual surgical residents (67 351 male individuals [60.0%]). The mean percentage of female trainees was 40.0% (44 835) and increased over the study period. Sex disparity remained greatest in orthopedic surgery. Residents who were underrepresented in medicine (URiM) comprised 14.9% (16 695) of all surgical trainees but demonstrated a 2.1% decrease over the study period. Overall attrition rate among all specialties was 6.9% (7759), with an unintended attrition rate of 2.3% (2556). Female residents had a significantly higher relative risk (RR) of attrition (RR, 1.16; 95% CI, 1.11-1.22; P < .001) and unintended attrition (RR, 1.17; 95% CI, 1.08-1.26; P < .001) compared with their male counterparts. URiM residents were at significantly higher RR for attrition (RR, 1.40; 95% CI, 1.32-1.48; P < .001) and unintended attrition (RR, 1.92; 95% CI, 1.75-2.11; P < .001) compared with non-URiM residents. The highest attrition (10.6% [746 of 7043]) and unintended attrition (5.2% [367 of 7043]) rates were in Black/African American residents. The lowest attrition and unintended attrition rates were seen in White residents at 6.2% (4300 of 69 323) and 1.8% (1234 of 69 323), respectively. Black/African American residents were at disproportionate risk for attrition (RR, 1.66; 95% CI, 1.53-1.80; P < .001) and unintended attrition (RR, 2.59; 95% CI, 2.31-2.90; P < .001) compared with all other residents. Orthopedic surgery had the highest attrition (RR, 3.80; 95% CI, 2.84-5.09; P < .001) and unintended attrition (RR, 7.20; 95% CI, 4.84-10.71; P < .001) for Black/African American residents. Results of this cross-sectional study suggest that the percentage of female residents in surgical specialties has improved over the last 18 years, and the percentage of URiM residents has remained relatively unchanged. Risk for attrition and unintended attrition was significantly elevated for female and URiM residents, specifically Black/African Americans. These results highlight current racial and sex disparities in resident attrition and demonstrate the importance of developing strategies to recruit, retain, and support residents.