Gyms in Pokémon Go allow Trainers to flex their Pokémon's muscle in an attempt to take over a Gym for their team—Team Instinct, Team Valor, or Team Mystic. In order to battle Pokémon at a rival team’s Gym, you must first reach Trainer Level 5, when you'll be prompted to select a team to join.
Choosing a team
While each team is essentially the same as far as game mechanics are concerned, you may consider checking out your nearby Gyms to see which teams are regularly in control. If one team has a monopoly on the area, you may not have as many opportunities to battle other Trainers’ Pokémon, nor will as many opportunities arise to put your own Pokémon on defense.
You can also opt to pick the team with the coolest Legendary bird mascot, or based on the personality of its Leader, which you get a slight insight into when choosing (though you can certainly perform some online research and find countless fan theories for each). You may want to consider this decision well, as you cannot change your team once you've selected. If you plan to regularly play with other Trainers, you may consider joining the same team so you can work together in taking down Gyms and defeating Raid Bosses, gaining additional bonuses for your team.
Assembling your Pokémon battle party
Once you’ve reached Trainer Level 5 and have selected your team, you’ll need to put together a party of Pokémon that you’ll use in battle. You can have up to six Pokémon in your party, and generally want to pick Pokémon with high CP and HP and those with types and moves which counter the defending Pokémon you'll be challenging. Trainers can put any Pokémon they choose in a Gym, though only one of each species can defend at a time, so it may be challenging to completely optimize your party.
Pokémon Go will automatically suggest a team of Pokémon, though it typically prioritizes based only on CP. If you want to be best equipped for the challenge, you'll want to ensure you're using Pokémon with effective moves. You can also create Battle parties to easily choose a pre-constructed team of Pokémon when challenging a Gym.
Understanding Gym battle mechanics
Battles in Pokémon Go differ greatly from their functionality in main series Pokémon games. Your Pokémon knows only two moves, and moves are categorized as Fast Attacks or Charged Attacks.
Fast Attacks can be used anytime and will add charge to your Charged Attack meter. Once this meter is full, your Pokémon’s Charged Attack can be used, dealing substantial damage. You can also dodge enemy Pokémon attacks by swiping left of right. The same battle mechanics apply when fighting Raid Bosses.
Once a Pokémon’s HP is reduced to zero in a battle, the Pokémon will faint and you are given the option to challenge it again until you've completely depleted its Motivation. For the purpose of completing Field Research missions which require Gym Battles, you only have to fight a single Pokémon battle. You aren't required to KO the Pokémon or clear our the entire Gym.
Claiming a Gym for your team
You can continue battling the Gym Pokémon until their Motivation has been completely depleted, at which time they'll be sent back to their Trainers. You can learn more about the ins and outs of Motivation, as well as how to help out your own team's Pokémon, in our complete guide to understanding Motivation and Gym defense in Pokémon Go.
Pokémon will be challenged in the order they were placed in the Gym. If you come up against a defender that you know your team won’t be able to handle, you may wish to end your battle early and save yourself the time (and consumable items).
Once all of the Pokémon have been removed from a Gym, it will turn grey on the map, and you can claim it for your own team by placing a Pokémon on defense. If Trainers from different teams are battling a Gym at the same time, whichever Trainer puts a Pokémon in first after clearing out the defenders will claim the Gym for their team. Of course, the other Trainer is then able to challenge that Pokémon.
Reviving and healing your Pokémon after battle
Unfortunately, any Pokémon defeated in battle will not automatically regenerate HP, and there's no Pokémon Centers offering a one-stop shop for reviving your team. Instead, you must use Revives on any of your Pokémon which have fainted and can restore their HP using a variety of Potions.
You can purchase these items from the in-game Shop in a pinch, but you'll generally get everything you need to keep your Pokémon healthy and happy by spinning Photo Discs at Gyms and PokéStops. You also have a chance to receive healing items in Gifts from Friends. Revives are a bit harder to get your hands on than the various potions, so you may wish to switch a low health Pokémon out of battle before it gets KO'd to avoid having to revive it after the fight.