So, in a restaurant, if you need to go, just say to the people with you "Veuillez m’excusez" (more formal), or just "Excusez-moi." Then get up and go towards an employee, and ask: "Où sont les toilettes s'il vous plaît" ("Where are the rest rooms please"). Easy enough.
If you get invited to someone's house, it's a bit more complicated. In the best-case scenario, the hostess will volunteer the info when she takes your coat or accompanies you to the living room. She'll say something like: "Les toilettes sont à gauche" ("The rest room is on the left") and you should memorize the door. If she doesn't, then plan on going before or after the meal. Wait for her to get up, follow her (but not into the kitchen, you have no place there in a formal household). Then ask discreetly: "Où est-ce que je peux me rafraichir?" ("Where can I freshen up?"). If you ask "Où est la salle de bains?" she'll think you want to take a shower, since toilets are often in a separate room... And rest room often have no sink. Learn to bear with it.
In a more relaxed setting, you can simply ask "Où sont les toilettes?", but do it discreetly, not in front of the other guests. And don't add "Parce que j'ai besoin de faire pipi." (cause I need to pee)!!
You will find many tips on French etiquette like this one in my lesson "French Table and Hosting Etiquette"

