It is very difficult indeed. Even more so for supply teachers (like me) who are often in classes where we know none of the students (so have no idea who might be trying it on) and where students are doing a load of pre-set cover work and are therefore more bored than in a normal lesson.
To suggest (as at least one poster did) that teenagers wouldn't be pretending they needed the toilet in order to get out of a lesson unless there was a problem and they needed more support is laughably naïve and comes across as though you've never met a teenager.
During one lesson the other day, I had 9 14yo students ask to go to the toilet. Absolutely no way of knowing who really needed to go. Once you let one go, the others start asking. It would be within almost any teenager's ability to be convincing. If you don't teach them regularly, you don't see a pattern of who asks all the time. I've been a teacher for over 20 years - I'm no rookie. As previous posters have said, SLT find kids vaping and making Tik Toks in the toilets.
If a girl asked to go and seemed genuine, I would let her go. But it still causes problems if you've said no or subsequently say no to other students. There is no easy answer to this.