Sex refers to biological traits, while gender is a socially constructed concept.
Sex typically refers to biological differences like chromosomes (XX, XY, things like that…), hormones, and reproductive organs, often classified as "male" or "female"; Gender -on the other hand- encompasses socially constructed roles, behaviors, expressions, and identities.
That's why you can change your gender but not your sex.