The fast gradient sign method (FGSM) is a single-step adversarial attack that perturbs an input by adding a small, fixed amount in the direction of the sign of the loss gradient, so that a trained model misclassifies an input that still looks unchanged to a human. In AI security, FGSM is the canonical example of an evasion attack and the standard baseline for testing and training robust models.
Ian Goodfellow, Jonathon Shlens and Christian Szegedy introduced the method in 2014 to support a key insight: neural networks are vulnerable to adversarial examples largely because they behave too linearly in high dimensions, not because they are too complex. A tiny change spread across thousands of input dimensions can add up to a large change in the output.
How FGSM computes an adversarial perturbation
FGSM builds the adversarial example in one gradient computation. The attacker computes the gradient of the model’s loss with respect to the input, takes only the sign of each component, multiplies it by a budget called epsilon and adds the result to the original input: x_adv = x + epsilon × sign(gradient of loss).
Using the sign rather than the raw gradient makes the perturbation maximal under the L-infinity norm: every input value moves by exactly epsilon, either up or down. The perturbed input is then clipped to the valid range, for example 0 to 1 for normalized pixels. Because it needs only one forward and one backward pass, FGSM costs about as much as a single training step.
| Component | Meaning | Effect on the attack |
|---|---|---|
| Loss gradient | Direction that increases model error | Points toward misclassification |
| Sign function | Keeps only plus or minus one per value | Uses the full budget in every dimension |
| Epsilon | Maximum change per input value | Controls strength and visibility |
| Clipping | Keeps values in the valid input range | Produces a realistic, valid input |
Epsilon, norms and targeted variants
The perturbation budget determines how strong and how visible the attack is. Values are usually quoted on the 0 to 255 pixel scale or as a fraction of the normalized range, and they depend heavily on the dataset.
| Dataset | Common epsilon | Visibility to humans |
|---|---|---|
| MNIST | 0.1 to 0.3 | Noticeable gray noise |
| CIFAR-10 | 8/255 | Barely visible |
| ImageNet | 2/255 to 16/255 | Mostly invisible at lower values |
The basic method is untargeted: it only increases the loss for the true label. A targeted variant subtracts the signed gradient of the loss for a chosen target class, pushing the model toward that specific wrong answer. Related work generalizes the step to other norms, for example the fast gradient method under the L2 norm, which scales the raw gradient instead of taking its sign.
Choosing epsilon is a threat-model decision, not a tuning exercise. The budget should reflect what an attacker could realistically change without detection, such as sensor noise levels or compression artifacts. Results are only comparable when papers state the norm, the epsilon scale and the preprocessing, because 8/255 on raw pixels differs from 8/255 applied after normalization.
FGSM compared with iterative and optimization attacks
FGSM is fast but weak compared with stronger attacks. Because it takes one linear step, it misses adversarial examples that require following the curved loss surface, so a model that resists FGSM may still fail against iterative methods.
| Attack | Steps | Relative strength | Typical use |
|---|---|---|---|
| FGSM | One | Weakest | Quick baseline, fast adversarial training |
| Basic iterative method | Several small FGSM steps | Stronger | Improved white-box evaluation |
| Projected gradient descent attack | Many steps with random start | Strong first-order attack | Standard robustness benchmark |
| Carlini–Wagner attack | Optimization-based | Very strong, minimal perturbations | Testing claimed defenses |
| DeepFool | Iterative linearization | Finds near-minimal perturbations | Measuring decision boundary distance |
FGSM is a white-box attack because it needs gradients. It can still threaten black-box systems through adversarial transferability: examples crafted on a substitute model often fool a different model trained on similar data, and single-step examples tend to transfer relatively well.
FGSM in adversarial training and robustness testing
Beyond attacking models, FGSM is widely used to make models more robust. In adversarial training, each batch is augmented with FGSM examples so that the model learns to classify perturbed inputs correctly. Its low cost made it the first practical way to harden large networks.
Single-step adversarial training has a known weakness called catastrophic overfitting: after some epochs, the model suddenly becomes robust to FGSM but loses almost all robustness against PGD. Two practical fixes are adding a random start before the FGSM step and using a slightly smaller step size, an approach often called fast adversarial training. Robustness must then be verified with PGD or stronger attacks, never with FGSM alone.
- Use FGSM as a smoke test in continuous integration to catch obvious robustness regressions.
- Report accuracy across several epsilon values, not a single point.
- Evaluate with stronger attacks before claiming any robustness level.
- Check for gradient masking when FGSM succeeds less often than random noise.
Limitations and misleading results
The most common error in evaluating defenses is treating FGSM resistance as real robustness. Defenses such as defensive distillation once appeared strong because they flattened or obscured gradients, a phenomenon called gradient masking, and they were later broken by optimization attacks and transfer attacks.
| Symptom | Likely cause | Recommended check |
|---|---|---|
| Iterative attacks weaker than FGSM | Gradient masking | Run attacks from random starts |
| Higher epsilon lowers attack success | Obscured or noisy gradients | Use black-box transfer attacks |
| Robust to FGSM, fragile to PGD | Catastrophic overfitting | Evaluate with multi-step PGD |
FGSM also assumes a digital, pixel-level threat model. Physical adversarial attacks must survive printing, lighting and viewing angles, and language models operate on discrete tokens where a sign step is not directly meaningful. These settings require adapted attack methods, and evaluation frameworks such as MITRE ATLAS and NIST AI 100-2 treat FGSM as one technique within a broader taxonomy.
The short version
FGSM is a quick way to trick an image classifier. It finds the small changes that would most confuse the model. Then it nudges every pixel a tiny bit in that direction.
To a person, the picture looks the same. To the model, a panda can suddenly look like a gibbon. Engineers use the same trick for defense. They show these altered images to a model during training. The model learns to ignore the noise. FGSM is fast, but it is a basic test. A model that survives FGSM is not automatically safe.
Where it makes a difference
A team building a visual defect detector for a factory line wants to know how fragile its model is before deployment. The convolutional classifier reaches 97 percent accuracy on clean images of metal parts.
The engineers run FGSM with epsilon values from 1/255 to 8/255. At 4/255, accuracy drops to 31 percent, even though the perturbed images look identical to inspectors. They retrain with FGSM examples generated from a random start, then evaluate with a 20-step PGD attack. Robust accuracy at 4/255 rises to about 70 percent, while clean accuracy falls only slightly, to 95 percent. The team adds an FGSM check to its release pipeline and schedules a full PGD evaluation before every model promotion.