Public restrooms are found in large cities, although you are not guaranteed to find one in an emergency. If you are in need, there are several options. You can enter the next café or restaurant and ask very politely to use the facilities. You can find a department store and look for the "WC" sign. Museums are also a good place to find facilities.
Train stations are increasingly turning to McClean, a privately run enterprise that demands €0.50 to €1.10 for admission to its restrooms. These facilities, staffed by attendants who clean almost constantly, sparkle. You won't find them in smaller stations, however. Their restrooms are usually adequate.
On the highways, the vast majority of gas stations have public restrooms, though you may have to ask for a key—we won't vouch for their cleanliness. You might want to wait until you see a sign for a restaurant.
Restrooms almost always cost money. It's customary to pay €0.20–€0.70 to the bathroom attendant.
To read up on restrooms in advance of your trip in Germany, the website www.lootogo.de is flush with sanitized info on restrooms across the country.