When two or more allies are positioned around an enemy, as such that a line between those allies crosses the space of the enemy, the allies gain the flanking bonus on their attack.
The flanking bonus consists of a +2 bonus to their attack.
This bonus is forgone if a player has advantage or disadvantage on their attack.
Example 1. The fighter and the cleric are flanking the ogre because they can draw a line to each other that passes through opposite sides of the ogre. Both the fighter and the cleric receive a +2 bonus on attack rolls made against the ogre.
Example 2. The rogue is not flanking the ogre because she cannot draw a line to the fighter or the cleric that passes through opposite sides of the ogre. The rogue cannot draw a line to the sorcerer because the sorcerer is not adjacent to the ogre and does not threaten it.
Example 3. The goblin and the ogre flank the sorcerer, as they can draw a line between them that passes through opposite sides of the sorcerer‘s square. If the ogre didn’t have reach to the sorcerer, though, he and the goblin would not be flanking her.