Gym

Gyms are scattered around the world much like PokéStops, but are not as common. Trainers can use them to train their Pokémon or to battle with other trainers' Pokémon.

Observing a gym on the world map will tell you a lot about it.
 * Grey Gyms are unclaimed by any team.
 * Blue Gyms are claimed by Team Mystic.
 * Red Gyms are claimed by Team Valor.
 * Yellow Gyms are claimed by Team Instinct.
 * Pokémon appearing above the gym are currently set to guard it, though if you tap the gym and scroll to the right, you may see additional Pokémon that are stationed there.
 * Lightning and rubble flashing above the gym indicates a battle is under way.

Unclaimed gyms appear grey and can be claimed simply by approaching it and assigning one of your Pokémon to it. Any Pokémon you assign to a gym will stay with that gym and be inaccessible to you until it is defeated by an opposing team member. If your Pokémon remains undefeated for 21 hours or more, you may claim the Defender Bonus.

Individual trainers can only leave one Pokémon to defend per gym, but gyms can be upgraded (or leveled up) to accommodate more and more Pokémon from other trainers of the same team. To do so, increase the gym's Prestige by winning friendly duel's with your team's Pokémon on that gym.

Strengthen a Gym
Assigning one of your Pokémon to an open Gym will claim it for your team. Strengthening a friendly Gym is done by assigning one of your Pokemon to help defend it.

An icon of a boxing glove that has a star on it should appear on the bottom right of your screen so you can train! When you train the Pokemon at a friendly Gym it will increase the Gym's Prestige and level.

As the Gym gains Prestige, its Prestige bar will fill up. When it is full, it will level up, and more Pokémon may be assigned to that gym. An unclaimed gym starts at level 2, and may be assigned 2 Pokémon from separate trainers. At level 3, it may have 3 Pokémon assigned, and at level 4, it may have 4 Pokémon assigned, etc. This continues until the Gym reaches level 10.

Defense
Gyms gain prestige through battles and by adding Pokémon to them. Trainers visiting a friendly gym can train their pokemon, and the gym will gain experience/prestige at the same time. Each time a gym reaches a new LVL, another pokemon is allowed to join the gyms defense.

Trainers with at least one pokémon defending a gym are eligible for the Defender Bonus.

Attack
Trainers visiting an enemy gym can battle the defending pokémon and bring the gyms LVL down if successful. Each successful battle will lower the gyms LVL by one, forcing it to remove one of it's defending pokémon. Defeating a LVL 1 gym will remove the last enemy pokémon, leaving the gym open to be claimed fresh.