🐦 Kids · Biology · Algorithms
📅 May 2026 ⏱ ~7 min read 🟢 All ages

How Do Birds Fly in Flocks?

A murmuration of starlings looks like a single living creature — hundreds of thousands of birds moving in perfect unison without any leader or plan. The secret? Each bird follows just three simple rules with its nearest neighbours. Complexity emerges for free.

The Mystery of Murmuration

A murmuration is the aerobatic display of thousands of European starlings (Sturnus vulgaris) at dusk. The whole flock rolls, pulses and reshapes like a living fluid — yet no single bird directs the others.

Scientists were puzzled for centuries. Early guesses included telepathy, air-pressure signals or a leader bird giving silent orders. The real answer, discovered in the 1980s, is far more elegant: each bird tracks only its seven nearest neighbours and obeys three local rules. Global beauty emerges from entirely local information.

Three Simple Rules

In 1986, computer graphics researcher Craig Reynolds created a program he called Boids (short for "bird-oids") that replicated flocking with just three steering rules:

📏

Separation

Steer away from any nearby boids that are too close — avoid collisions.

🎯

Alignment

Steer to match the average direction and speed of nearby boids.

Cohesion

Steer towards the average position of nearby boids — stay together as a group.

Just these three rules are sufficient to reproduce flocking, schooling fish, swarming insects and herding mammals. Reynolds's 1987 paper won an Academy Scientific and Technical Award for its use in Hollywood films.

The Maths Behind the Rules

Each boid has a position vector p and a velocity vector v. On every time step, we compute three acceleration contributions and add them to the velocity.

Separation

For each neighbour j closer than a separation radius r_sep, subtract a repulsion vector weighted by distance:

separation_force += (p_self - p_j) / |p_self - p_j|²

Alignment

Average the velocities of all neighbours within radius r_align and steer towards that average heading:

alignment_force = mean(v_neighbours) - v_self

Cohesion

Steer towards the average position (centre of mass) of neighbours within r_cohesion:

cohesion_force = mean(p_neighbours) - p_self

Each force is scaled by a weight constant, then all three are added to the current velocity. The velocity is then clamped to a maximum speed so boids don't accelerate forever.

Minimal JavaScript Implementation

// For each boid, find neighbours and compute forces
function updateBoid(b, others) {
  let sep = {x:0,y:0}, ali = {x:0,y:0}, coh = {x:0,y:0}, n = 0;
  for (const o of others) {
    const dx = b.x - o.x, dy = b.y - o.y;
    const d = Math.hypot(dx, dy);
    if (d < RADIUS_SEP && d > 0) {
      sep.x += dx / (d * d);
      sep.y += dy / (d * d);
    }
    if (d < RADIUS_VIS) {
      ali.x += o.vx; ali.y += o.vy;
      coh.x += o.x;  coh.y += o.y;
      n++;
    }
  }
  if (n > 0) {
    ali.x = ali.x/n - b.vx; ali.y = ali.y/n - b.vy;
    coh.x = coh.x/n - b.x;  coh.y = coh.y/n - b.y;
  }
  b.vx += sep.x * W_SEP + ali.x * W_ALI + coh.x * W_COH;
  b.vy += sep.y * W_SEP + ali.y * W_ALI + coh.y * W_COH;
  // clamp speed, then move
  const speed = Math.hypot(b.vx, b.vy);
  if (speed > MAX_SPEED) { b.vx *= MAX_SPEED/speed; b.vy *= MAX_SPEED/speed; }
  b.x += b.vx; b.y += b.vy;
}

Emergence: More Than the Sum of Parts

Flocking is a classic example of emergence: complex collective behaviour that arises from simple individual rules without any central control. The flock as a whole exhibits properties that no single boid has.

Other examples of emergent systems:

Emergence vs. swarm intelligence: Emergence is the phenomenon; swarm intelligence is engineering that uses emergence to solve problems (robotics, logistics, optimization algorithms).

Real-World Applications

The Boids algorithm and variants of swarm intelligence are used in many fields:

Try It Yourself

You can explore flocking behaviour interactively in the simulations below:

Experiment idea: In the Boids simulation, set cohesion to zero. What happens? Now set alignment to zero. How is the behaviour different? This reveals the distinct role each rule plays in producing the emergent flock.
🐦 Open Bird Flock →