The general idea of flanking is to attack the enemy from all available angles to increase the advantage of your attack. Available unit composition and positioning can greatly increase or decrease the effectiveness of being flanked. Here is outlined various unit positions and its effects on being flanked.
General Ideas Behind Unit Positioning & Flanking
If a general were to decide which to engage - 50 Marines 1 time or 1 Marine 50 times - a general is most likely to choose the second option. One Marine fifty times is far easier to destroy because the total amount of DPS against one Marine is the highest and the Marine's DPS is at its lowest. Thus, flanking takes advantage of increasing your own DPS while weakening your opponent's ability to damage you.
There are four common unit positions and layouts which are seen in Starcraft II - Concave, Convex, Spread, and Ball positions. Each position has its unique advantages and disadvantages which can steamroll the opponent given the correct situation.
The concave unit position is the most aggressive stance. It is a curved position which allows all of your units to focus fire on a unit contained in the center point outside of the concave curve (hereafter referred to as "center point"). While being the most aggressive stance, it is also the weakest to flanking. Attempting to attack the enemy from the center point will maximize the enemy's damage. However, attacking from either side (the top or the bottom) allows you to attack each unit one at a time which vastly increases your DPS. Furthermore, attacking a concave from the behind also increases your DPS due to fighting a convex curve (see below), but the advantage is not nearly as good as attacking from one of the more vulnerable sides.
There are some units which perform very well against concave curves - the most notable one being the Colossus because its attack naturally follows a concave curve across the battlefield. As such, a Colossus maximizes its damage when fighting a concave curve and is the sole exception to fighting from within the center point.
A convex curve is one which curves away from the center point. If the concave curve is flipped along the Y-axis, you would see a convex curve. A convex curve is less aggressive than a concave curve, but it is also more defensive than a traditional concave curve. This is because there are only two sides from which a convex curve is weak - the top and the bottom. This unit positioning also requires more micro as Starcraft II naturally defaults to a concave curve.
It's extremely common for ground melee units - Zerglings and Zealots in particular - to find themselves in concave and convex curves. Generally the units which have the concave position have a large advantage due to the increased aggression that the curve naturally allows. Whichever side is in the convex position is obliged to retreat and return with more forces. In mirror matches, generally the unit composition which is concave will win a large percentage of the time. It is still possible for the convex curve to win with proper micro (retreat and return micro being the most obvious).
A spread formation is best for units which cause friendly fire through splash damage. Using a concave or convex position could work with units that cause friendly fire, but the issue is generally with melee units causing splash damage. The fewer units that are affected by splash damage from friendly fire, the better. The primary beneficiary from a Spread formation is the Siege Tank since it benefits from having increased geographic cover and less friendly fire from splash damage.
It can be incredibly difficult to flank a Spread position since there is no inherent weak point to attack from any given angle (assuming the spread position is in a square). Because the only weak points of the Spread position is directly next to each unit within the spread formation, this leads to Zealot Bombing or Marauder bombing.
The main units which tend to ball up are Marines, Marauders, and Zerglings. The best way to think about a ball is merely a Convex curve that has been folded in on itself many times. Thus, a ball is the most defensive position that a unit composition can take since it vastly decreases the risk of the innermost units being attacked. Its obvious disadvantage is splash damage since all of the units are bunched together. A more extreme version of this is the deathball (see below).
Unit positioning is extremely important with the Ball formation. It's best to put heavier units, Marauders, at the outside while keeping weaker units, Marines, on the inside. This decreases the chance of the weaker units being destroyed quickly by splash damage (Banelings, Siege Tanks, Infestors) and allows these high DPS units to fire upon the enemy.
Another possible way to counter the Ball formation is to use ranged units with a very long range. In this manner, you can then use an infinite concave curve (circle) to surround the opponent completely. In this manner, the outer ring of units can be taken out while the inner units do not have the range to fire outside of the ball. This can be particularly hard to achieve as the ball must be caught off guard in an open area while you have units which can engage in this fashion from afar.
Using the Terrain
One of the best ways to enhance your unit positioning is by using the terrain for yourself and against the opponent. For example, Zealots are much stronger against Zerglings when against the wall. This means Zerglings cannot get a surround on the Zealots and allows them to last much, much longer. Other ways to use the terrain are placing magic casters (High Templar, Raven) on the high ground where ground forces cannot see them - then strike with auto-turrets or Seeker Missiles against enemies unaware. Although ground units can attack from the top of a cliff without fear of counter-attack as long as the opponent does not have vision, any flying units that attack from over a cliff immediately give away their position and the opponent can attack back. Keeping the opponent in the dark about where and how your units can attack his through superior unit positioning is often the key to victory.
The so-called deathball is a technique where a player or players gathers all of their forces into a single group and marches around the map killing everything in their path. Most common with Zerg and Protoss, the opponent has to either counter with a deathball of their own, try to pick it apart, or to try and quickly base trade, winning the game by eliminating all enemy structures.
There are alternative ways to win via positioning. Engaging a deathball at multiple angles maximizes one's damage output against the deathball.