Domain tracks · L2Client prediction and lag compensation

Client prediction and lag compensation

The server owns the truth, but players cannot wait for it. Learn how games predict your moves, fix them quietly, and rewind time to judge shots fairly.

L2 SeniorDomain tracks18 min read
Fact-checked by AI against cited sources · Human review pendingLast reviewed 21 Oct 2026 · How we check content
Senior at work · lesson 25 of 26
Section 1 of 8

What broke

A made-up story to show a common failure. Not about a real company.

This story is made up, but each part of it happens in real games.

A small studio ships an online shooter. Each player's game decides what happened and tells the server: "I moved here. I hit player 7." The server passes the news on. It feels fast.

In the first week, cheaters arrive. A changed client reports a headshot on every enemy. The server believes it. Honest players quit.

The team moves the truth to the server. Now your game sends only "I pressed forward" and waits to hear where you are. Cheating gets much harder. But now every step starts a fraction of a second after you press the key. The game feels slow.

The team needs both: a server that cannot be fooled, and a game that reacts at once. This lesson shows how real games get both.

Section 2 of 8

The idea in simple words

The server is the authority. Gabriel Gambetta's rule is short: "don't trust the player." A hacked client may claim 10000% health. The server still knows the real value, so the player still dies. 1 VALORANT is built the same way. Riot writes that its server "must never trust a client's view of the world". 6

But the network is slow. Light alone would need about 13 ms to cross the 4,000 km from San Francisco to New York. Real internet paths are slower. Gambetta says delays of 100, 200 or even 500 ms are not unusual. A half-second delay makes a game unplayable. 1 The time for a message to go to the server and come back is called the round-trip time, or ping. 5

So games use three tricks, one for each kind of thing on your screen:

  1. Your own character: predict. Move at once, as a guess. Fix the guess when the server answers.
  2. Other players: interpolate. Show them a little in the past, between two real updates.
  3. Shots: lag compensation. The server rewinds time to what the shooter saw, then checks the hit.

The key idea. The server decides what is true. The client decides what you see right now. Prediction, interpolation and lag compensation are ways to hide the gap between the two, and each one has a price.

Section 3 of 8

How it works

Tick rate: how often the server updates

The server runs the game in small, fixed steps called ticks. In each tick it reads player inputs, moves everything and checks the rules. In Valve's Source engine, the default tick is 15 ms, about 66 ticks per second. 5 A higher tick rate is more exact, but it needs more CPU and bandwidth. 5 VALORANT runs movement at exactly 128 steps per second, on both client and server. 6

The server does not send every tick to every player. It sends snapshots of the world at a set rate. In Source, a client receives about 20 snapshots per second by default. 5

Client-side prediction

Without prediction, you press forward and see nothing until the server answers. Valve's example: with 150 ms of latency, you see your own move 150 ms late. 5

With prediction, your game runs the same movement code as the server, at once. You move now. The server still has the final word. 5 This works well only if the game is deterministic enough: the same state plus the same inputs should give the same result. 2

Server reconciliation

Prediction has a trap. The server's answer is always old by the time it arrives. If you copy it, you jump backwards. Step through the fix below. It follows Gambetta's example: 250 ms of lag, and two presses of the right arrow. 2 Use Next and Back, or the ← and → keys.

Client prediction and server reconciliation: move now, fix quietly later Your game Server x = 11 (guess)input #1 x = 12 (guess)input #2 x = 11 · did #1x = 11, last #1arrives at 250 ms reset to x = 11replay #2 → 12no replay: jumps to 11 x = 12 · did #2x = 12, last #2✓ matches · nothing to replay SeniorPath
  1. You press the right arrow. Your game does not wait. It moves you from x = 10 to x = 11 at once, as a guess, and sends input #1 to the server.
  2. You press right again. Your game guesses x = 12 and sends input #2. The server has not answered yet, because the network is slow.
  3. The server runs input #1 and says: you are at x = 11, and the last input I used was #1. This answer reaches you 250 ms after you pressed.
  4. x = 11 is old news. If you just copied it, your character would jump back. Instead, your game resets to 11, keeps input #2, which the server has not seen yet, and replays it. You stay at 12.
  5. Later the server runs input #2 and says x = 12, last #2. This matches your guess, and no inputs are left to replay. You never saw a jump.
Step 1 of 5

The fix needs two small things. 2

  • Numbered inputs. Each input gets a sequence number: #1, #2, #3.
  • Acknowledgement. Each server update says, "this is your state after input #N."

The client throws away inputs up to #N. It resets to the server's state and replays the inputs the server has not seen yet. Riot uses numbered, fixed-size moves in the same way. When a client says "I simulated move #408", the server knows exactly which move it means. 6

Sometimes the guess is truly wrong. Maybe another player blocked your path. Then the client must move you to the server's position. Source can spread this fix over a short time, so the view does not jump. 5 In VALORANT, only the player with the bad network sees the fix. The other nine players keep smooth movement. 6

Entity interpolation for other players

You can predict yourself because you know your own key presses. You cannot know another player's. 5 Gambetta describes dead reckoning: assume the player keeps the same speed and direction. It works for cars or ships. It fails for players, who run, stop and turn very quickly. 3

So games show other players in the past. They draw smooth movement between the last two real updates. 3 Source does this with a 100 ms delay by default. With 20 snapshots per second, one lost snapshot still leaves two real ones to draw between. 5 The result: you see yourself in the present, and everyone else about 100 ms ago.

Lag compensation: the server rewinds time

Now you aim at an enemy and fire. You aimed at where they were on your screen, which is in the past. By the time your shot reaches the server, they have moved. Without help, you would have to aim ahead of moving targets. 6

Lag compensation fixes this on the server. Source keeps one second of recent player positions. When your shot arrives, the server estimates when you fired 5:

fire time = server time − packet latency − your interpolation delay

It moves the other players back to that moment, checks the hit, and puts them back. 5

Why not let the client say "I hit him"? Valve's answer: a server cannot trust clients with such decisions. Even a clean client's packets could be changed on the way by a "cheat proxy". 5

The price: shot behind a wall

Rewinding time favours the shooter. You can reach cover on your screen and still die, because the server checked the shot at an earlier moment, when you were still in the open. Valve says this "can't be solved in general". 5 Gambetta calls it "somewhat unfair", but "the most agreeable solution for everyone involved". 4

So games limit the rewind. Riot writes that without limits, a player with 500 ms latency could kill you half a second after you reached cover. 6

Peeker's advantage

The same delays help the attacker. When you step around a corner, you see the defender at once, thanks to prediction. The defender sees you only after your move goes to the server and on to them, plus buffering. 6

Riot added up these delays. With its model's assumptions, the peeker had about 141 ms longer to react. Lower network latency, with a target of 35 ms ping, and 128-tick servers cut about 40 ms of that. With those changes, a client running at 144 frames per second (FPS) brings it down to about 71 ms. 6 Small numbers matter. In Riot's blind tests, skilled players noticed changes of about 10 ms. 6

A glimpse of rollback netcode

Some fast games are peer-to-peer, with no central server. Each player's machine runs the full game. The old way was to wait for the other player's inputs, which feels slow. 7 Rollback netcode predicts the other player's inputs and keeps going. When the real inputs arrive and differ, it re-runs the game from the point where they differed. Like prediction, this needs a fully deterministic game. 7 See lockstep and rollback netcode.

Section 4 of 8

Trade-offs

TechniqueWhat you gainWhat you payUse it for
Wait for the serverYes Always correct and simple.No Every action is late by the round-trip time.Slow games, like turn-based games.
Client-side predictionYes Your own moves feel instant.Shared, deterministic code. Small fixes when guesses are wrong.Your own character's movement and actions.
Dead reckoningOthers look current.No Big jumps when a player turns suddenly.Things that move in a steady way, like cars or ships.
Entity interpolationYes Smooth, and uses only real positions.Others are shown about 100 ms in the past.Other players in fast games.
Lag compensationYes Shots hit where you aimed.Targets sometimes die behind cover. Needs a rewind limit.Hit checks in shooters.
Rollback netcodeYes No input delay for local inputs.Must save, load and re-run game states fast. Needs full determinism.Fast peer-to-peer games, which GGPO was built for.
Section 5 of 8

At work: how a senior uses this

  • Ask first: "Who is the authority for this piece of state?" Health, money, hits and inventory belong to the server.
  • Write a latency budget. List network, buffering, tick and frame time in milliseconds, like Riot's peeker's advantage sum.
  • Test with fake lag and packet loss (network data that never arrives) from day one. Prediction bugs hide on a fast office network.
  • Keep movement code shared and deterministic, with a fixed time step.
  • Log every correction. A rise in corrections after a release means client and server code have drifted apart.
  • Set a maximum rewind time for lag compensation, and write down who it is unfair to.
  • Notice the pattern outside games. An app that shows a "like" before the server confirms it is predicting, and needs a plan for when the server says no.
Section 6 of 8

With AI

What to ask the agent

"Here is our movement code for client and server. List every place where the two could give different results for the same input, such as floats, random numbers, frame time or order of updates."

"Write a test that runs 1,000 random inputs through the client predictor and the server, with 150 ms of fake latency, and checks that the final positions match after server reconciliation."

"Explain our lag compensation code step by step. What is the maximum rewind time, and where is it set?"

What to check yourself

  • The agent did not move any authority from the server to the client "to make it faster".
  • Inputs carry sequence numbers, and acknowledged inputs are dropped. Otherwise the replay list grows forever.
  • The tests use real lag, jitter and packet loss, not only a perfect local network.
  • Any number in a latency budget comes from your own measurements or a cited source.
  • The rewind limit is a deliberate choice that you can explain to players.
Section 7 of 8

Check yourself

1. Why do most competitive shooters let the server, not the client, decide where players are and who got hit?

Show answer

A player can change their own client, so the game cannot trust what it says. Gambetta's rule is "don't trust the player". A hacked client can claim anything, so only the server's version counts.

2. Your game predicted you at x = 12. The server's update says x = 11, last input processed

Show answer

Reset to x = 11, drop input This is server reconciliation. The server's state is true but old, so the client replays the inputs the server has not seen yet.

3. Why do clients show other players about 100 ms in the past instead of guessing where they are now?

Show answer

Other players can change direction at any moment, so guesses would often be wrong and jump around. You cannot know another player's next key press. Interpolating between two real updates is smooth and uses real positions, just a little late.

4. A player complains they were shot after they reached cover. What is the most likely cause?

Show answer

Lag compensation. The server judged the shot at the moment the shooter saw them, before they reached cover. Valve and Gambetta both describe this side effect. Rewinding time favours the shooter, so the target can be hit after reaching cover.

5. Riot found that skilled players could notice a change in peeker's advantage of about how much?

Show answer

About 10 ms. In Riot's blind tests, skilled players noticed changes of about 10 ms, and 20 ms felt very large to them.

Your progress is saved only in this browser. Export it to keep it safe.

Was this clear?
Report a mistake (opens GitHub in a new tab)
Section 8 of 8

Go deeper

Show 7 sources and related lessons
  1. Gabriel Gambetta, “Fast-Paced Multiplayer (Part I): Client-Server Game Architecture” (opens in a new tab)
    Why the server must be the authority, and why waiting for the server makes a game feel slow.
  2. Gabriel Gambetta, “Fast-Paced Multiplayer (Part II): Client-Side Prediction and Server Reconciliation” (opens in a new tab)
    The step-by-step example with input numbers that this lesson's diagram follows.
  3. Gabriel Gambetta, “Fast-Paced Multiplayer (Part III): Entity Interpolation” (opens in a new tab)
    Why you cannot predict other players, dead reckoning, and showing others slightly in the past.
  4. Gabriel Gambetta, “Fast-Paced Multiplayer (Part IV): Lag Compensation” (opens in a new tab)
    How the server rebuilds the past to judge a shot, and the fairness cost.
  5. Valve Developer Community, “Source Multiplayer Networking” (archived copy, January 2026) (opens in a new tab)
    Real defaults from the Source engine. Tick rate, snapshots, interpolation, prediction and the lag compensation formula.
  6. Matt deWet and David Straily, “Peeking into VALORANT's Netcode”, Riot Games Technology (2020, archived copy) (opens in a new tab)
    How Riot measured peeker's advantage in milliseconds and cut it, plus fixed time steps and rewind limits.
  7. GGPO, “Rollback Networking SDK for Peer-to-Peer Games” (opens in a new tab)
    A short, plain explanation of rollback netcode from the library that made it popular.

Case studies: Riot Games: Making VALORANT servers 20 times faster for 128 tick · Riot Games: Shrinking peeker's advantage in VALORANT's netcode

Related: Tick rate, snapshots and bandwidth (coming soon) · Authoritative servers and anti-cheat (coming soon) · Deterministic lockstep and rollback netcode (coming soon) · The game loop and fixed timestep (coming soon) · Latency numbers and back-of-envelope maths

Term

See full entry

Jump to a section

  1. 1What broke
  2. 2The idea in simple words
  3. 3How it works
  4. 4Trade-offs
  5. 5At work
  6. 6With AI
  7. 7Check yourself
  8. 8Go deeper