There are 4 so-called gym levels you can achieve. When you spin the gym stop, you get awarded a gym badge. This is at basic level (Picture #3 - right). After you earn 500xp for that gym (e.g. defending, feeding berry, spin stop, defeating another team's mon in the same gym, RAID) you get upgraded to a bronze badge (Picture #2 - middle). Then When you earn up to 4000xp you get upgraded to silver (Picture #1 - left) and when you hit 30,000xp upgraded to gold (Err... i dont have yet). Based on what i've experienced, silver badge earns around 5-6 items (5 probably if your team isn't controlling).
This is how you earn:
Bronze Additional XP 500 XP Total XP 500 XP
Silver Additional XP 3500 XP Total XP 4000 XP
Gold Additional XP 26,000 XP Total XP 30,000 XP
1) Adding Pokémon to the Gym (+ 100 Badge XP)
2) Holding a creature at the Gym (+1 Badge XP per minute)
3) Defeating a defending Pokémon (CP of Pokémon defeated divided by 10)
4) Winning a Raid battle (+ 1000 Badge XP)
5) Giving Berries to Pokémon held at the Gym (+ 10 Badge XP, as well as 20 Stardust and a possibility of Candy)
* So, in conclusion, to level up a gym badge from basic to bronze to silver to gold is similar like levelling up your TL from Level 28 to 30 to 33... the grind gets harder and takes longer. Hope this helps.
** Btw, if you purely put a mon in an empty gym and don't feed it a berry, it would need to stay there for 20 days for you to earn a gold badge... just saying... LOL
thanks for the detailed explanation, i get it now.
anyway, i feel that this -> Defeating a defending Pokémon (CP of Pokémon defeated divided by 10) isnt accurate, because i see the gym xp only increase about 10-20 each time.