When you reach level five, Professor Willow introduces you to gyms and the option to choose your affiliation–Instinct, Mystic, or Valor. There is one of three scenarios that may appear when you are close enough and can tap on a Pokemon Gym. Either the Gym is unclaimed (white), owned by a rival team, or owned by your own chosen team.
If you interact with a gym representing your team, you can either train your Pokemon for XP by battling others or store them there for bonus Poke Coins and Stardust, which can be claimed once every 21 hours. However, when you encounter an opposing team’s gym, you can only do battle with its Pokemon. If you defeat its entire roster, you’ll take a large amount of Prestige Points away from that gym. High-level gyms with a large amount of Prestige Points may need to be defeated multiple times before they can be claimed.
Originally Posted by: gamespot.com