You'll find everything you need to know about winning battles and conquering gyms in this article. For that you need to reach level five first and then;
Find a Pokémon Gym
Just like PokéStop Gyms are well-marked on the Pokémon Go map. Gyms on map appear as tallest landmarks. Tapping on those marks will let you know where exactly, it exists in the real world but before level 5, visiting a gym won't do too much. The Professor will pop up to tell you come back once you're a bit more experienced. Once you reach level 5, you can battle. Choose a team affiliation wisely, Instinct (Yellow), Mystic (Blue), or Valor (Red).
How to Fight at Neutral, Friendly, or Enemy gyms
Once you've chosen a team (Instinct, Mystic or Valor), you can fight at gyms. They're marked in three ways these are neutral, friendly, or enemy.
To claim a neutral gym you need to assign one of your Pokémon to hang out and fight for you and your team, (can be claimed by any one of the three teams). But you can only assign one of your Pokémon per gym. When gym is claimed, it becomes a level 2 friendly or enemy gym, and has a spot for up to one other Pokémon from a member of that faction.
When a member of your faction holds the gym, you can spar amongst your teammates to raise your gym's prestige and it will raise the level too (the higher the gym's level, the more Pokémon that your different team members can station there). Gyms level ranges from level 2 to level 10 (two to ten Pokémon from different members of your faction), and order is from lower combat power to higher.
Once the Pokémon is added to a friendly gym, it'll live their at the gym until it's been conquered. Choose the Pokémon wisely because you'll have to leave that Pokemon and you won't have access to train your Pokémon until it's been returned after the conquering. When training at a gym, you can choose just one Pokémon to spar with your teammates. Winning a fight will raise your gym's prestige and level.
At enemy gyms you fight at an opposing gym to reduce your opponent's prestige and eventually conquer it for your own team. Here, you can use up to six of your Pokémon against the up to 10 gym leaders. Winning will net you personal experience points and remove your enemy's claim to that gym.
Winning Fights, Fighting at Gym
To be the best Pokémon Trainer, you have to level up some Pokémon. And No, you don't level up your Pokémons by fighting other ones in the wild but earning Stardust and Candy (by catching Pokemon). These two items help Power Up your Creatures. Here's the tip; Avoid using your Stardust until you reach level 20 and start catching higher-level base Pokemons. But if you still want to start battling early just spend it on one or two Pokémon to start out, and save for level-20.
Match up Pokémon with their opposing types before a battle, you can damage enemy's gym prestige if you know how to match up an opposing Pokémon's type and element.
Build a good lineup
You need to build a good lineup at enemy gyms as at friendly Gym, you'll just have one Pokémon to fight. At enemy gym you can swap between your Pokémons at any time during a fight, you can tap swap Pokémon button to choose a different creature mid-fight. It'll help if your Pokemon isn't being effective or running low on health.
Dodge and Attack
During Gym battle, when "Go!" command is given you can hit opponent's Pokémon. To attack tap anywhere on the screen, you'll see a "Very effective!" or "Not very effective," followed by a drop in their HP or a "Dodged!" if they avoided your attack. Be quick and don't wait, the best way to win a battle is the art of the Dodge. Dodging opponent's attack needs perfect timing, you can dodge any attack your opponent throws. Your Pokémon might still face a little damage but it'll help.
You can dodge by watching for the speed lines. Look for the speed lines emanating from the attacking Pokémon and swipe left or right to avoid the attack. Once you've dodged, now you might be able to get in one or two basic attacks because opponent's Pokémon will take time to reset. Watch for the lines and damage-dodge-damage,
Now when basic attacks will build enough damage you will see the blue bars underneath your HP light up and glow (time to launch special attack). Tap and hold on the screen to unleash your top-tier battle move. While this is happening, you cannot dodge an opponent's attack or make other fight moves.
Now if you've conquered a gym you'll have to leave your Pokemon their (to defend it). After conquering a gym, you can visit the Shop once every 20 hours to collect free Pokécoins and some extra Stardust.
Got something in your mind? Feel free to ask in comment section.