TL;DR
Secure aggregation lets a server learn the total of many private numbers without learning any single one. Each device hides its number behind random masks, and the masks are arranged so that they cancel exactly in the sum. Each message on its own looks like random noise, and when the server adds the messages, the masks vanish and the true total remains.
Builds on: Secret Sharing, Federated Learning, Modular Arithmetic · Leads to: Differential Privacy
Where it's used
Typing models on phones. A keyboard model can improve its suggestions if it learns which words are typed often across many phones, but the server should not learn what any one phone typed. The protocol was designed by researchers at Google for federated learning on phones. Phone keyboards, which learn from what many people type, are a natural example of this kind of workload.
Counting feature use on user devices. Suppose a product team wants to know how many users turned on a setting. With secure aggregation, each device contributes a masked 0 or 1, and the analytics server receives only the total. No single user's choice reaches the server in the clear. This is an illustration of the pattern, not a claim about a specific deployment.
Pooling totals across organisations. In a setting like a group of banks each holding private records, each bank can contribute a number, such as its total exposure to one kind of risk, and a coordinating server gets the combined figure. The banks never reveal their branch-level numbers. Again, this is an illustrative case.
How it works
Take a tiny instance. Three devices hold private numbers 2, 5 and 9. All arithmetic is done modulo 10, so every value is a digit from 0 to 9. The server should learn only the total, which is 16 mod 10 = 6.
- Agree on pairwise masks. Every pair of devices agrees on a secret random number between 0 and 9 that nobody else knows. Devices 1 and 2 share the mask 3, devices 1 and 3 share 8, and devices 2 and 3 share 4. Check: each pair has exactly one mask, and the server never sees any of them.
- Add masks to higher partners, subtract masks from lower ones. Device 1 has no lower partners, so it adds both of its masks: 2 + 3 + 8 = 13, which is 3 mod 10. Check: device 1 sends 3, which tells the server nothing about the 2 it started with.
- Apply the same rule to the others. Device 2 subtracts the mask it shares with device 1 and adds the one it shares with device 3: 5 − 3 + 4 = 6. Device 3 subtracts both of its masks: 9 − 8 − 4 = −3, which is 7 mod 10. Check: the three messages are 3, 6 and 7.
- The server adds the messages. 3 + 6 + 7 = 16, which is 6 mod 10. Check: this equals the true total of 2 + 5 + 9.
- Why the masks cancel. Each mask appears twice, once with a plus sign in the lower device's message and once with a minus sign in the higher device's message. The mask 3 appears as +3 in device 1 and −3 in device 2. The mask 8 is +8 for device 1 and −8 for device 3. The mask 4 is +4 for device 2 and −4 for device 3. Check: each pair contributes zero to the sum.
- Why one message reveals nothing. The server sees the message 3 from device 1, but it does not know the mask 3 was added. The same message 3 would appear if device 1's private number were 0 with a different mask, so the message is consistent with every private value. Check: the server cannot pin down device 1's number from its message alone.
The walkthrough assumes every device answers. Secret sharing and the dropout example later in this lesson show what happens when one does not.
flowchart LR X["Device i holds private x_i"] --> M["Add masks shared with higher ids, subtract masks shared with lower ids"] M --> Y["Masked message y_i sent to server"] Y --> S["Server adds all messages"] S --> T["Masks cancel, leaving the total of the x_i"]
The math
Let devices hold private inputs in the integers mod , written . A protocol securely aggregates these inputs if the server learns the sum and nothing about each beyond what that sum reveals.
Here is the set of [[modular-arithmetic|integers wrapped around modulo ]]. Unlike Secret Sharing, the modulus need not be prime, because no division is needed: the protocol only adds and subtracts.
Step 1 in symbols: the pairwise masks
For every pair of devices , the two devices agree on a mask drawn uniformly from . Only and know it. In practice the pair first agrees on a shared key with a key-agreement method such as Diffie-Hellman, then expands that key with a pseudorandom generator. A pseudorandom generator is a deterministic procedure that stretches a short seed into many numbers that look random to anyone who does not know the seed. In the tiny instance, , and .
Step 2 in symbols: the masked message
Device sends
The first sum adds the masks shared with higher-indexed devices. The second sum subtracts the masks shared with lower-indexed devices. For the tiny instance, , and .
Step 3 in symbols: the masks cancel
Add up all the messages:
In the last double sum, rename the indices: write and , so the pair becomes and the term becomes . The two double sums then range over exactly the same pairs, so they are equal and cancel:
Check with the tiny instance: .
Step 4 in symbols: one message reveals nothing
Suppose the server knows but not the masks, and at least one mask in is unknown to it. Call the sum of the masks in the number . Because one of its terms is a random variable that is uniform and independent of everything the server knows, is uniform over . For any fixed , the map is a bijection, so is uniform whatever is. This is the same argument as the one-time pad, with the mask playing the role of the key.
Step 5 in symbols: dropouts
Suppose device does not send . Let be the set of devices that did send, and the set that did not. The masks linking survivors to dropped devices are still inside the survivors' messages, so the sum of the received messages is off by a residual :
Here when and when , matching the sign rule in Step 2. If the survivors together reveal enough of the material needed to rebuild the masks tied to each dropped device, the server can compute and subtract it. That recovery is where Secret Sharing enters the protocol.
Worked examples
Device 1 holds 4 and device 2 holds 3. They share the mask 6, and every sum is taken mod 10.
- Device 1 has the lower index, so it adds the mask: . It sends 0.
- Device 2 has the higher index, so it subtracts the mask: . It sends 7.
- The server adds the messages: .
- The true total is . The two agree.
- The message 0 does not reveal device 1's input. Without the mask, a message of 0 could come from input 4 with mask 6, from input 0 with mask 0, or from any other pair that sums to 0 mod 10.
The server learned the total, and the individual messages did not show either input.
Devices 1 to 4 hold inputs 1, 6, 4 and 8, so the true total is . The pairwise masks are , , , , and .
- Device 1 adds its three masks: . Its message is .
- Device 2 subtracts the mask with device 1 and adds the masks with devices 3 and 4: . Its message is .
- Device 3 subtracts the masks with devices 1 and 2 and adds the mask with device 4: . Its message is .
- Device 4 subtracts all three of its masks: . Its message is .
- The server adds the messages: .
- Check the masks: , so they cancel.
Device 3's masks happen to sum to 0. That is a coincidence of these numbers, not a rule.
Four phones count how often a word was typed in one day: 3, 0, 5 and 2. The modulus is 100 so the hand arithmetic fits. Real systems use far larger moduli and many more devices. The pairwise masks are , , , , and . Phone 3 goes offline before sending its message.
- Phones 1, 2 and 4 send their messages: , and . The masked parts , and are the sums of each phone's signed masks.
- The server adds the three messages: .
- Read naively, this suggests the survivors' total is 80. The true survivors' total is , so the report is off by 75.
- The residual is the sum of the masks linking survivors to phone 3. Phone 1 contributes , phone 2 contributes , and phone 4 contributes . So .
- The surviving phones together reveal enough of phone 3's key material, shared out with secret sharing, that the server can rebuild those three masks. No survivor reveals its own input or its own mask.
- The server subtracts the residual: , which matches .
Try it: suppose the server skipped step 5 and reported 80 as the survivors' total. By how much is the report wrong, and what number should it have subtracted to get the right total? Answer: it is wrong by 75, since the report is 80 and the true total is 5. It should have subtracted the residual 75.
Common mistakes and tradeoffs
It is tempting to think that secure aggregation hides everything from the server. In fact the server learns the total, and when the group is small the total can reveal a lot. If only one device reports, the total is that device's input. Protocols therefore set a minimum group size, and many systems add Differential Privacy noise to the total so that one person's data cannot be read off it.
It is tempting to think that the masks must be random for the sum to come out right. In fact cancellation is pure arithmetic: any values work as long as both partners add and subtract the same mask. Randomness matters only for privacy. If the masks were predictable, the messages would leak their inputs even though the sum was still correct.
It is tempting to think that dropouts are harmless because the other devices still report. In fact a dropped device leaves residual masks in the sum, and the server's total is wrong without any error message. Recovering from dropouts takes extra rounds and Secret Sharing, and if too few devices survive to meet the threshold, the total cannot be recovered at all, so the round should be discarded.
It is tempting to think that the server gets nothing if it lies. The protocol described here assumes an honest-but-curious server, which follows the steps but tries to learn what it can. A server that sends different keys to different devices, or that falsely reports who dropped, can learn more, so practical protocols add consistency checks.
When to use it: many devices each hold a number, you need only their sum, and the server is trusted to follow the protocol but not to see inputs. When not to use it: you need each device's own output, you must withstand a server colluding with devices, or the group is too small to hide anyone. Alternatives include Homomorphic Encryption, where the server adds ciphertexts without decrypting them, and trusted hardware that performs the sum inside a sealed device.
History
In 2016, McMahan and colleagues introduced federated averaging, which trains a federated model by sending model updates to a server instead of raw data. Those updates can still reveal information about the data they came from, so the server should not see each one in the clear. That gap is what secure aggregation was built to close.
The masking idea, in which random values are added and arranged to cancel, predates federated learning and comes from the multi-party computation literature. In 2017, Bonawitz and co-authors at Google published a protocol at the ACM CCS conference that combined pairwise masking with secret sharing, so that the total could be recovered even when phones dropped out partway through a round.
It caught on because phones are unreliable. They lose connectivity, run out of battery, and close apps. A masking scheme that worked only when every device answered would be useless in practice, and the dropout recovery is what made the approach workable at scale.
Recap
- Each pair of devices shares a secret mask. The lower-indexed device adds it and the higher-indexed device subtracts it.
- The masks cancel in the sum, so the server gets the true total modulo from the messages alone.
- A single masked message looks uniformly random, by the same argument as the one-time pad, as long as one of its masks is unknown to the server.
- When devices drop out, their masks remain in the sum. Survivors reveal enough secret-sharing material for the server to rebuild and subtract the residual.
- Read next: Differential Privacy, which limits what the released total itself can reveal, and Homomorphic Encryption, an alternative that lets a server compute on encrypted values.
Check yourself
QuestionRecall: what does the server learn in a secure aggregation protocol, and what must it not learn?Show answer
It learns the sum of the inputs modulo . It should learn nothing about any individual input beyond what that sum reveals.
QuestionComputation: three devices, modulus 10, inputs 3, 8 and 6, masks , and . Find each masked message and the server's total.Show answer
Device 1 adds its masks: . Device 2 subtracts the mask with device 1 and adds the mask with device 3: . Device 3 subtracts both of its masks: . The server adds . The true total is , so the messages are 8, 1 and 8 and the total is 7.
QuestionWhy: why does one masked message reveal nothing about its input, even though the masking rule is public?Show answer
The masks are secret and uniformly random, and the server does not know them. For any fixed input, adding a uniform unknown mask produces a value that is equally likely to be any number mod . So the message has the same distribution for every input, and it carries no information about which input was used.
QuestionApplied: a team runs secure aggregation over 50 phones. On some nights the server total is far below what the phones should have sent, and the gap grows on nights when many phones go offline. What is the likely cause, and what should the team check?Show answer
The likely cause is that the residual masks left by the offline phones are not being removed. The team should check that the recovery step rebuilds and subtracts the residual from the survivors' sum, and that the survivors' shares meet the threshold. If too few phones survive to meet the threshold, the total cannot be recovered and the round should be discarded rather than reported.