The reliable way is to check the anatomy. Males have a penis and, in most cases, testes; females have a vulva and udder development.
A few other clues help in practice: stallions and geldings tend to be more muscular through the neck and shoulder, while mares often carry a slightly finer build. None of those are definitive on their own, so anatomy remains the answer.