Course contentsShow
← Security
Lesson 2810 of 3,05253. AI and ML SecurityFree lesson

FGSM: Fast Gradient Sign Method

Learning the foundational single-step gradient-based attack that adds noise in the direction of the loss gradient.

FGSM: Fast Gradient Sign Method

What you'll learn: How to craft adversarial examples using a single-step gradient attack that exploits the direction of maximum loss.

The Core Idea

The Fast Gradient Sign Method (FGSM) is the simplest and fastest adversarial attack against machine learning models. Instead of iteratively optimizing noise to fool a model, FGSM takes a shortcut: it calculates the gradient of the loss function with respect to the input, then adds a small amount of noise in the direction that maximizes that loss.

Think of it like this: if you're trying to make a model misclassify an image, you need to know which pixels, when changed slightly, will confuse it most. The gradient tells you exactly that — it's like a map showing "push this pixel brighter" or "push that pixel darker." FGSM simply follows that map one step in the "wrong" direction (from the model's perspective).

How It Works

Given an input image x, the correct label y, and a trained model with loss function L:

  1. Compute the gradient of the loss: ∇ₓL(x, y)
  2. Extract just the sign of each gradient value (+1 or -1)
  3. Add small perturbation: x_adv = x + ε · sign(∇ₓL(x, y))

The parameter ε (epsilon) controls perturbation magnitude. Common values are 0.01–0.1 in normalized pixel space.

Why It Matters

FGSM is computationally cheap (single gradient calculation) and surprisingly effective. It exposes the fundamental vulnerability: neural networks are linear in high-dimensional spaces, so adding carefully aligned noise in many dimensions accumulates into significant misclassification.

Key Takeaway: FGSM demonstrates that even single-step, gradient-based perturbations can fool ML models by exploiting the linearity of loss landscapes — forming the foundation for understanding adversarial robustness.