Flanking
Rules glossary
Advantage on attack rolls against a shared foe is the payoff flanking offers combatants, an easy option for tables that regularly play with miniatures.
Flanking needs a creature that can see the enemy and is not incapacitated. For a Large or larger creature, one qualifying square or hex anywhere in its space is enough: as long as at least one does, it is flanking.
Flanking on Squares
An enemy is flanked when a creature stands adjacent to it with at least one ally also adjacent, positioned at opposite sides or corners of its space; every member of that flanking group gains advantage on melee attack rolls against the enemy.
A line from the center of one creature's space to the center of the other's settles any doubt on a grid about whether two creatures flank an enemy: the enemy is flanked if that line crosses opposite sides or corners of its space.
Flanking on Hexes
On hexes, each flanker gains advantage on attack rolls against the enemy it flanks, and flanking there takes a creature and at least one ally standing next to that enemy on opposite sides of its space. Opposition is checked by counting hexes around the enemy from one creature to its ally, and the gap required grows with the enemy's size: 2 hexes between them against a Medium or smaller creature, 4 against a Large creature, 5 against a Huge one, and at least 6 against a Gargantuan one.