Gym Badges were introduced as part of the highly anticipated gym re-work Niantic rolled out in June of 2017. The first time you spin a gym you receive a unique badge for that gym. Everything you do at that gym from then on will earn you Gym XP towards leveling up that Gym Badge to Bronze, then Silver, and finally Gold.

Trainers are also awarded Bonus Items each time they spin a gym that are dependent on what level Gym Badge has been obtained.

Gym Badge Levels
Badge Level Total Gym XP Bonus Items
Bronze 500 XP 1
Silver 4,000 XP 2
Gold 30,000 XP 3

The most time efficient way to level up Gym Badges is by completing raids. Regardless of the Tier, each raid battle yields you 1,000 Gym XP. Meaning that if you do 30 raids at that gym you will have enough Gym XP to get the Gold Gym Badge for it.

Other ways to obtain Gym XP are deploying a Pokemon into a gym, fighting opposing Pokemon in gyms, feeding berries to Pokemon already deployed in gyms (which also nets you a bonus 20 Stardust per berry fed), and having a Pokemon deployed in a gym over time.

How to earn Gym badge experience

How To Obtain Gym XP
Completing a Raid 1,000 Gym XP
Deploy a Pokemon into a Gym 100 Gym XP
Defeat an Opposing Pokemon in a Gym Defender CP / 100
Feeding berries 10 Gym XP per Berry (20 Stardust per Berry)
Keeping Pokemon in a Gym 1 Gym XP per minute defending

When defeating a Gym, you will earn XP as a coefficient of the defenders Combat Power. For instance, a 3200 CP pokemon would net you 32 Gym XP. To determine the total Gym XP you would gain from taking down a gym you do this for each individual battle and add it all up.

As far as defending gyms goes, you gain 1 XP per minute the Pokemon stays in the gym. As a result, it takes just under 21 days defending to get enough Gym XP for a Golden badge.

Navigating gym badges

To view a list of all the Gym Badges you have obtained, go to your trainer profile, scroll down to the Gym Badges, then click on “List”:

Gym Badges are sortable by Name (A-Z), Defending (you have a pokemon deployed), Recent (most recently visited gyms), and Points (Gym XP). You can also pull up a world map showing the locations of all your badges.

To view a list of pokemon have you deployed in gyms, go to your pokemon storage and use the search term @defender. This will show only the pokemon you have deployed in gyms and allow you to remotely feed them berries (10 Gym XP each)