Skip to content
Velloreth
Gaming 10 min read

Multiplayer Netcode Explained

How multiplayer games hide latency: prediction, reconciliation, interpolation, lag compensation, lockstep, and rollback — and which model fits which genre.

By

Every multiplayer game is fighting the same opponent: the speed of light through fibre and copper. A player in London talking to a server in Virginia waits roughly 70–90 ms round trip; across continents it is 200 ms or more. Nothing in software reduces that number. Netcode is the set of techniques for making that wait invisible — or at least survivable.

Once you accept that, the design space gets smaller and clearer. There are a handful of techniques, they compose in specific ways, and the right combination depends almost entirely on what kind of game you are making.

The anatomy of the delay

When a player presses a button, four delays stack up before anyone sees a result:

StageTypical costFixed?
Input to client simulation< 1 msYes, if you predict
Client to server (one-way)15–150 msNo — geography
Server simulation at its tick0–16.6 ms at 60 HzYes, given tick rate
Server to affected clients15–150 msNo
Interpolation delay at the receiver1–2 ticks usuallyYes, tunable

At 100 ms round trip and a 60 Hz server tick, a naive implementation gives you roughly 120–150 ms before your own shot appears to fire. That is slow enough to change how a game feels — Street Fighter players built an entire tactical vocabulary around it, which the community calls “lag tactics.”

Transport: UDP, with your own reliability layer

TCP is the wrong tool for state updates. Its guarantee of ordered delivery means one lost packet blocks every packet behind it until retransmission completes — head-of-line blocking. At 2% packet loss, a 60 Hz stream of state updates spends a visible fraction of its time stalled.

Games run on UDP and add a thin reliability layer themselves:

  • Unreliable for continuous state: positions, velocities, animation states. A lost update is superseded by the next snapshot anyway; waiting for the old one would be worse than not having it.
  • Reliable-ordered for discrete events: match start, round result, chat, item grant. Small volume, must arrive, must arrive in order.
  • Unreliable-sequenced for things like explosion effects: deliver if they arrive in time, drop them if they arrive late and something newer is already showing.

Implementing that layer is less work than it sounds — a sequence number, an ack bitfield, and a retransmit list — and it is the first thing to get right, because every technique above it depends on knowing which data you actually have.

Ticks, snapshots, and bandwidth

The server runs a fixed simulation tick and periodically serialises world state into a snapshot sent to clients. Three numbers define your budget:

  • Simulation rate — 60 Hz is the standard for action games; 30 Hz is workable for slower ones.
  • Snapshot rate — often lower than the simulation rate (a 60 Hz sim sending 20 Hz snapshots is common) or equal.
  • Payload — where the real engineering is. Sending full state every snapshot is prohibitive; you send deltas against the last snapshot a given client acknowledged, only for entities that client currently relevants.

Interest management — culling entities outside a player’s relevant set, by distance, visibility, or gameplay zone — is usually a bigger bandwidth win than any compression trick. A battle royale with 100 players does not send 100 players’ state to everyone; it sends the nearby subset, and the far subset is updated at a much lower rate.

Client-side interpolation then smooths the gap. The client renders remote entities about 100 ms in the past, between the two most recent snapshots, so movement looks continuous instead of teleporting at each packet. That interpolated past is also what lag compensation later needs to reconstruct.

Authoritative server, predicting client

The dominant architecture for shooters and action games, from Valve’s Source engine networking onward, combines three ideas:

Client-side prediction for the local player. The client simulates its own movement immediately, without waiting for the server, so input feels instant. Nobody perceives their own character as laggy, because the client never waits.

Server reconciliation. The server also simulates the player, using the client’s inputs, and sends back authoritative state. The client keeps a ring buffer of the inputs it has sent but not yet confirmed, and when the server’s state arrives, it rewinds to that point, applies the server’s result, and replays the unconfirmed inputs on top. If prediction was correct, the replay is a no-op and nothing visibly changes. If it was wrong — the server said you hit a wall the client did not know about — the correction happens in the past, and the player sees a small snap rather than a rubber band.

Lag compensation on the server for hit detection. When the server processes a shot, it rewinds all other entities to the position they occupied on the shooter’s screen at the moment the trigger was pulled — using the client’s command tick and the server’s stored history. That is why you can be hit by someone who appears to have already taken cover: the server is validating a shot against a world state up to one round trip old.

Lag compensation is also why it must be bounded. Servers keep a history window (commonly a few hundred milliseconds) and clamp rewind depth, so a client with terrible latency cannot rewind the world arbitrarily far. Excessive rewind is a cheat vector, not a feature.

Lockstep: determinism instead of state

Real-time strategy and classic fighting games took a different route. Instead of sending state, they send inputs, and every peer runs the identical deterministic simulation.

The result is tiny packets — one input per player per tick, not a world snapshot — at the cost of an absolute requirement: same inputs, same binary, same results, bit for bit. That means no floating-point divergence, no iteration order depending on a hash map, no wall-clock reads, no thread scheduling in the sim.

The failure mode is worse than any other model: a single desync corrupts the entire match state, and the only recovery is a rollback or a disconnect. Determinism is not a setting you enable; it is a discipline applied to every line of simulation code.

Rollback: predict, rewind, resimulate

Rollback came to prominence through Tony Cannon’s GGPO, written for fighting games where frame-accurate timing is the gameplay and any added input delay changes how the game plays.

The model, in one sentence: assume the remote input will be the same as last frame, simulate immediately, and if the real input arrives late or differs, rewind to the first wrong frame, apply the correct inputs, and re-simulate forward.

local input  ──► simulate immediately (always)
remote input ──► assume "same as last frame"
                    │
                    ▼
              real input arrives
                    │
          ┌─────────┴─────────┐
          │ matches prediction │──► nothing to do
          └─────────┬─────────┘
                    ▼ mismatch
        rewind to frame N, re-simulate to present

The engineering consequences are substantial. The simulation must be deterministic. State must be cheap to snapshot every frame (a ring buffer of the last N states). Resimulation must be fast, because a mismatch can cost up to the whole rollback window re-run. And rendering must handle entities teleporting — the classic visual artifact is the remote character sliding or snapping when a prediction is corrected.

The knobs, as described in implementation write-ups of shipping fighting games:

ParameterTypical valueEffect of raising it
Rollback window6–8 framesMore tolerance for late input, more resimulation cost
Fixed input delay0–3 framesSmoother for both sides, but slower local response
Max input delay~50 msHides latency before prediction kicks in
Max predicted time~100 msClient simulates further ahead, more possible misprediction

Delay-based netcode and rollback are not rivals so much as points on a spectrum: delay trades responsiveness for perfect visual consistency, rollback trades occasional visual correction for perfect responsiveness. Games commonly blend them — a small fixed input delay plus rollback reduces mispredictions while keeping response near-instant.

FPS games sit between the models: they predict the local player (like rollback) but do not resimulate the world from inputs; they correct remote entities toward server-authoritative positions. That hybrid is cheaper than full rollback and adequate because a shooter does not need frame-exact determinism for every entity.

Cheating, authority, and what you must not trust

Any client-side simulation opens an obvious question: what stops a client from lying?

The rule is simple, and the implementations vary only in how strictly they apply it. The client proposes; the server disposes. Movement is validated against server-side speed and collision rules. Shots are validated against server-side hitboxes and the bounded lag-compensation rewind. Items, damage, and economy are resolved server-side only.

Prediction is safe because it is cosmetic: the client renders a guess, and the server’s authoritative state overwrites it. What is not safe is letting a predicted result become a fact before the server confirms it — that is how speed hacks and damage bugs happen.

Testing: simulate the bad networks first

You cannot debug latency you cannot reproduce. Build artificial network conditions into your game early:

  • Latency: 50 / 100 / 200 ms round trip.
  • Jitter: ±20–50 ms variance, which is what real mobile and Wi-Fi connections add.
  • Packet loss: 1%, 3%, 5%, applied to UDP deliberately.
  • Reordering and duplication: rare, but real on some paths.

Expose them as a developer menu so designers and QA can reproduce player reports. Then add determinism checks for anything using rollback or lockstep: hash simulation state each tick on each peer and compare; a desync should be loud and immediate, not discovered at the end of a tournament.

Choosing your model

GameUsual choiceWhy
FightingRollback (GGPO-style)Frame data is gameplay; input delay changes the game
RTS / card battlerDeterministic lockstepInputs are tiny; simulation is discrete
Tactical shooterAuthoritative server, prediction, lag compHit fairness matters more than perfect prediction
MMO / ARPGClient interpolation, server authority, heavy interest managementEntity count makes bandwidth the binding constraint
Co-op PvEAuthoritative server, generous interpolationCheating pressure is low; smoothness matters
Sports / racingPrediction plus interpolation, physics-syncedVehicle physics need shared determinism at the margins

If you are starting from zero: build an authoritative 60 Hz server, UDP with a small reliability layer, delta snapshots, client-side prediction for the local player, and interpolation for everyone else. That covers the majority of genres. Add rollback only when you have a concrete reason — a fighting game, or a turn-based game that needs instant local response.

What to take away

Netcode is not one algorithm; it is a stack of decisions about who simulates what, when, and who is believed. Latency itself is not negotiable, but almost everything above it is: you can hide your own player’s delay with prediction, hide remote players’ delay with interpolation, rewind the server to match what a shooter saw, or rewind the simulation to correct a mispredicted input.

Pick the model your genre demands, build the instrumentation to see it working, and then tune. The teams that struggle are rarely using the wrong technique — they are using the right one without the ability to watch it fail on demand.

Frequently asked questions

What is the difference between lag compensation and client-side prediction?
Prediction runs the local player's simulation ahead of the server so their own input feels immediate. Lag compensation does the opposite on the server: it rewinds world state to the moment the shot was fired on the client's screen, so hit detection matches what the shooter saw. They solve different halves of the same latency problem.
Why do fighting games use rollback instead of delay-based netcode?
Delay-based netcode adds a fixed input delay to keep both simulations in sync, so everyone feels the worst player's ping. Rollback assumes remote inputs will arrive on time, simulates immediately, and rewinds a few frames if a prediction was wrong — local input stays instant and mismatches appear as brief visual corrections instead of constant sluggishness.
What tick rate should my game use?
60 Hz simulation is the standard for action games, with snapshot send rates of 20–60 Hz depending on bandwidth. Higher ticks improve fidelity and cost CPU; 30 Hz is workable for slower games but is visibly worse for hit detection. Pick the rate first, then design the snapshot format around it.
Can I use TCP for a multiplayer game?
Not for real-time action. TCP guarantees ordered delivery, so one lost packet stalls every packet behind it — head-of-line blocking turns a 2% loss rate into visible stutter. Games use UDP with a small reliability layer on top: unreliable for state updates, reliable-ordered only for events like match start and chat.