Next time just raise your hand and say, "May I be excused?" The teacher will understand.
If you were at someone's house, you would say, "May I use your bathroom?" Australians say, " Can you show me where the loo is?"
If you were at a restaurant you could say, "Where are your rest room/conveniences?"