Toilet

The toilet, also referred to by the Ferengi as a waste extraction fixture, is a device used for the disposal of bodily wastes. The waste extraction system was the system used to manage and process that and all other related wastes.

During the first mission of the starship, Captain Jonathan Archer declared that the Vulcan High Command didn't think Humans could flush a toilet without a Vulcan to assist. 

In 2151, Worley Elementary School in Kenmare, County Kerry, Ireland on Earth, sent questions, letters, and drawings to the Enterprise. One question asked was "When you flush the toilet, where does it go?" and one of the few that was answered personally – Captain Archer delegated it to chief engineer Trip Tucker. Commander Tucker was not pleased with the captain's selection of questions for him and protested, but ultimately relented and explained to Molly the ship's processes of recycling and biomatter resequencing. 

The brig aboard Starfleet ships included facilities such as a sink and toilet, which were enclosed behind the wall until needed. A sign above the toilet read "do not use while in spacedock."

Waste extraction points on a Bajoran transport are located in individual quarters. After Ibudan was murdered in 2369, Dr. Julian Bashir located seofurane fragments near the waste extraction point in Ibudan's quarters on the transport. 

The Ferengi shuttle, Quark's Treasure was equipped with a waste extraction unit. 

It was said that the waste extraction fixtures at the Nagal Residence on Ferenginar were plated with latinum. Quark, believing that he was about to become the next Grand Nagus, said that the first thing he was going to rip out the plated fixtures and replace them with solid latinum fixtures. 

His upcoming wedding with Leeta and preparations for a Dominion attack on Deep Space 9 in late 2373 made Rom so nervous that he announced he had to go to waste extraction. 

Background information
According to the Star Trek: The Next Generation USS Enterprise NCC-1701-D Blueprints, the door in Jean-Luc Picard's ready room led to a bathroom. The blueprints also referred to the bathrooms as both "toilets" and "heads". The main bridge of the USS Enterprise (NCC-1701-D) featured a bathroom just off the doors leading to the observation lounge. In the authorized re-creation of the main bridge in Star Trek: The Experience at the Las Vegas Hilton, the inscription on the doors read "HEAD". The head was visible in a few episodes, but although it was not in focus enough to read the inscription, the length of the inscription changed between episodes during the seventh season. In addition, in episodes throughout the seventh season, multiple crew members can be seen simultaneously entering the bridge via the head. It is unclear how many toilets are available for use in the head on the main bridge.

According to Jonathan Frakes during the "Journey's End: The Saga of Star Trek: The Next Generation" special in 1994, the Enterprise-D had only one bathroom and he proceeded to point to it on the large cross-section of the Enterprise-D in the main engineering set.

As for how it works, as Bashir said in, best not to dwell on it too much.