Skip to content

Lesson 1 of 6 · 8 min read

Adversarial Examples and Evasion

Free lessonReviewed By the AISecurityInterviews editorial team
Reading position
In this lesson

TL;DR: An adversarial example is an input altered by a small, deliberately chosen perturbation that makes a model err, while people see no meaningful change. Evasion attacks craft them at prediction time: white-box with the model's gradients (FGSM, PGD), black-box with queries, or by transfer from a substitute model. The core reason they exist is that models rely on features humans do not. Defences: adversarial training (raises robustness against the perturbations trained on), certified robustness (provable guarantees in small regions), and system-level controls. Evaluate defences against adaptive attackers; many have fallen to them. LLM jailbreaks found by optimisation are the same phenomenon in text.

Before you read

Pick an answer before you read further. The lesson below explains it, and guessing first, right or wrong, helps the explanation stay with you.

  1. 1A malware classifier is 99.5 percent accurate on a held-out test set. Does that tell you how it performs against malware authors?

What makes an example adversarial

In 2013, Szegedy and colleagues showed that image classifiers could be made to misclassify images by adding perturbations too small for people to notice. Goodfellow and colleagues (2014) explained the effect partly as a consequence of models behaving almost linearly in high-dimensional input spaces, and introduced the fast gradient sign method (FGSM): nudge every input feature a small step in the direction that increases the model's loss.

Three properties make this a security problem:

  1. Small perturbations, large effects. The change is bounded (for example, each pixel moves by a few intensity levels), yet the prediction flips with high confidence.
  2. Transferability. Examples crafted against one model often fool other models trained for the same task, so attackers do not need the target model.
  3. Physical realisability. Researchers have produced adversarial patterns that survive printing and photography, such as stickers that cause road-sign misclassification (Eykholt et al., 2018).

The threat model has numbers

"Robust to adversarial examples" means nothing until three parameters are fixed.

  • The norm measures how the perturbation is counted. The ℓ∞ norm caps the change to any single feature; ℓ2 caps the overall size of the change; ℓ0 caps how many features change at all.
  • The budget, ε, is the maximum size under that norm. For small images a common research setting is ℓ∞ with ε = 8/255: each pixel value, on a 0 to 1 scale, may move by at most about 0.031.
  • The goal is either untargeted (any wrong answer) or targeted (a specific wrong answer, which is harder and usually what an attacker wants).

Norms are not interchangeable, which is why a claim must name one. A 32 by 32 colour image has 3,072 values. An ℓ∞ budget of 8/255 lets every one of them move by 0.031, which adds up to an ℓ2 size of up to about 1.74. A defence certified at ℓ2 = 0.5 therefore says nothing about that ℓ∞ attacker, and the reverse holds too.

Attacker knowledge

SettingAttacker hasTypical approach
White-boxModel architecture, weights, gradientsGradient-based optimisation: FGSM, projected gradient descent (PGD)
Black-box, score-basedQuery access with confidence scoresEstimate gradients from scores
Black-box, decision-basedQuery access, labels onlySearch near the decision boundary
TransferA similar substitute modelCraft on the substitute, apply to the target

PGD (Madry et al., 2017) repeats small gradient steps and projects back into the allowed perturbation budget, producing much stronger attacks than one FGSM step. It is the standard baseline for evaluating robustness.

LESSON · ADVERSARIAL EXAMPLES AND EVASION
Evasion at prediction time

Original input

Classified correctly

Perturbed input

Looks the same

Fixed model

Threats

Attacker

  • Gradients or queries
1/3

Normal prediction

The model classifies the original input correctly.

A cautionary history: defences that only looked strong

The adversarial examples literature is the best-documented case in AI security of defences that passed their authors' tests and failed against a better attacker. Interviewers for ML security roles expect you to know it.

WorkYearFinding
Carlini and Wagner2017Defensive distillation had cut earlier attacks' success from 95% to 0.5%. Their new attacks succeeded 100% of the time on both distilled and undistilled networks
Athalye, Carlini and Wagner20187 of 9 white-box defences accepted at ICLR 2018 relied on obfuscated gradients; 6 were fully and 1 partially circumvented
Tramèr and colleagues202013 defences from top venues, each evaluated by its authors against adaptive attacks, were circumvented with attacks tailored to them
Croce and Hein (AutoAttack)2020A standard ensemble of attacks applied to more than 50 published models found lower robust accuracy than reported for all but one, often by more than 10 percentage points

The common failure is gradient masking: a defence that makes gradients useless to the attacker's optimiser without removing the vulnerability. The model is still wrong near the input; the attacker's map is just broken. Attacks that approximate the gradient differently, or that do not need one, walk straight through.

LESSON · ADVERSARIAL EXAMPLES
One defence, two evaluations

Evaluated with a standard attack only

Defence distorts gradients

Standard PGD stalls

gradient masking

High robust accuracy reported

Outcome, unsafe: Robustness overstated

The vulnerability is hidden, not removed.

Adaptive attack plus a standard ensemble

Attack designed around the defence

Ensemble baseline as a floor

AutoAttack-style

Lower, honest number

Outcome, safe: A claim you can rely on

In one review, reported figures fell by more than 10 points for most models.

1/2

What fooled reviewers

Defences that break the attacker's optimiser look strong against the attack they were tuned for.

Defences and their limits

  • Adversarial training trains on adversarial examples generated during training (typically with PGD). It is the most reliable empirical defence, at a cost in clean accuracy and compute, and it protects mainly against the perturbation type and size it was trained on.
  • Certified robustness provides a mathematical guarantee that no perturbation within a small radius changes the prediction, for example randomised smoothing (Cohen et al., 2019). Guarantees cover small radii and specific norms.
  • Input transformations and detection (denoising, compression, detecting adversarial inputs) have repeatedly been broken. Athalye, Carlini and Wagner (2018) showed that many published defences relied on masking gradients and fell to adaptive attacks.
  • System-level controls often matter more: limit query access, require multiple independent signals for high-stakes decisions, keep humans in the loop for consequential outcomes, and monitor for probing.

The evaluation rule from this literature is worth remembering everywhere in AI security: a defence is only as good as its performance against an adaptive attacker who knows the defence.

Certified robustness, with a real number

Certification gives a proof rather than a test result: for a given input, no perturbation within radius r under a stated norm can change the prediction. The best-known scalable method, randomised smoothing (Cohen, Rosenfeld and Kolter, 2019), certified 49% top-1 accuracy on ImageNet against ℓ2 perturbations up to 0.5.

That radius sounds generous until it is spread across an image. A 224 by 224 colour image has 150,528 values; an ℓ2 budget of 0.5 spread evenly moves each one by about a third of one intensity level out of 255. Certification is real and valuable, but at practical scales it covers small perturbations under one norm, and accuracy under certification is far below a normal model's.

Robustness has costs

  • Accuracy. Tsipras and colleagues (2018) showed that robustness can be provably at odds with standard accuracy for some data distributions, matching the clean-accuracy drop seen in practice.
  • Why it happens. Ilyas and colleagues (2019) argued that adversarial examples exploit non-robust features: patterns in the data that genuinely predict the label but are brittle and imperceptible to people. A model that uses every predictive pattern will use those too.
  • Privacy. Song, Shokri and Mittal (2019) measured six adversarial-training defences and found they increased membership inference risk: hardened models can reveal more about whether a record was in the training set. A hardening project should include a membership inference audit.

Worked example: reading a robustness claim

A vendor says its image classifier for content moderation is "92% robust". Before that number means anything, ask:

QuestionWhy it matters
Which norm, budget and goal?92% at ℓ∞ 2/255 untargeted is a very different claim from 92% at 8/255 targeted
Which attacks, and how strong?PGD with how many steps and restarts; was a standard ensemble run as a floor?
Was the attack adaptive to this defence?Most broken defences passed non-adaptive tests
What is the clean accuracy?Hardened models often lose accuracy on ordinary inputs
Empirical or certified?An empirical number is an upper bound that a better attack can lower; a certified one is a proof for the stated radius

Without answers, "92% robust" is a marketing figure. With them, it becomes a claim you can compare and test, and for a moderation system you would still pair it with rate limits on probing, human review of borderline cases and monitoring for evasion patterns.

LESSON · EVALUATING ROBUSTNESS
Questions that turn a robustness number into a claim
1/3

Define the adversary

Without a norm, a budget and a goal, there is nothing to be robust against.

Evasion in language models

Text is discrete, which makes gradient attacks harder, but the idea carries over. Zou and colleagues (2023) used gradient-guided search to find adversarial suffixes, strings appended to a prompt that caused aligned models to comply with requests they would refuse, and some suffixes transferred across models. Jailbreaks and prompt injection that slip past classifiers are close relatives of evasion: the attacker searches for inputs on the wrong side of a learned boundary. That is why filters cannot close the gap on their own.

NIST's taxonomy of adversarial machine learning (NIST AI 100-2, 2025 edition) classifies evasion alongside poisoning, privacy and abuse attacks and is a useful reference for vocabulary.

Misconceptions interviewers listen for

  • "Keeping the weights secret prevents evasion." Transfer and query-based attacks work without them.
  • "It resists PGD, so it is robust." Gradient masking fooled reviewers repeatedly; demand adaptive attacks.
  • "Adversarial training fixes it." It helps within the trained threat model, costs clean accuracy and can raise privacy leakage.
  • "Certified means secure." Only within a small radius under one norm.

What if · interview follow-ups

Hold your answer as the constraints change

Your company buys an image classifier for content moderation and is considering an adversarially trained version. The interviewer probes evasion, evaluation and trade-offs.

  1. Start here

    What does an attacker need to know to evade this classifier?

How this shows up in interviews

"What is an adversarial example, and how is it different from an ordinary error?" opens many ML security interviews. Strong answers say it is an input chosen by an adversary to cause a specific error, contrast it with natural errors on the data distribution, explain white-box versus black-box and transferability, and describe adversarial training and certified robustness honestly, including the adaptive-attack lesson. Connecting it to LLM jailbreaks shows breadth.

Say it in 30 seconds: "An adversarial example is an input with a small, deliberately chosen perturbation that makes a model err while looking unchanged to people. It's evasion: the model is fixed and the attacker works at prediction time, with gradients like FGSM or PGD in white-box, queries in black-box, or transfer from a substitute model. Adversarial training and certified robustness help within limits, many detection defences have been broken by adaptive attacks, and optimised jailbreak suffixes are the same idea in LLMs."

Check yourself

Say or write your answer first, then reveal. Explaining it from memory, in your own words, is the skill an interviewer is checking.

  1. 1Why does transferability make black-box API access a weaker defence than it seems?

  2. 2A paper reports a new adversarial-example detector with 98 percent detection on standard attacks. What would you ask before deploying it?

  3. 3Why must a robustness claim state the norm and the budget?

  4. 4What is gradient masking, and how is it detected?

Practise it as an interviewer asks it

Related lessons