They are different, because a man can identify as a woman while being biologically a man.
A woman can identify as a man while being biologically a woman.
It's simple, really.
Gender relates to identity, sex relates to biology.
They are different concepts.