Well the short answer is that you memorize the structure and charges of the polyatomic ions (nitrate, nitrite, sulfate, suflite, carbonate, phospohate, etc). At least that's how I did it in highschool and it worked just fine. A longer and perhaps more insightful answer is below.