Gender differences in students' physics identity in introductory physics courses can influence students' interest in science, technology, engineering, and mathematics and their career decisions. Exploring the components that influence these identities is critical to developing a better understanding of the underrepresentation of women in physics courses and physics-related majors. We used a revised version of the physics identity framework developed by Hazari et al. [J. Res. Sci. Teach. 47, 978 (2010)] to investigate whether the relation between gender and physics identity was mediated by motivational factors, such as competency belief, interest, and perceived recognition by others. We surveyed approximately 500 students in introductory level calculus-based physics courses in which 30% of the students are women. Analysis revealed that the relation between gender and physics identity was mediated by students' selfreported motivation at the end of the semester. The model showed that perceived recognition by others played a major role in students' endorsement of physics identity with female students less likely to endorse statements that others perceived them as a "physics person."