Epochs, Batches, and Iterations

What Are Epochs, Batches, and Iterations?

These three concepts describe how data flows through a machine learning model during training. Together, they control how and how often the model updates its parameters.

Definitions

Epoch — One full pass through the entire training dataset

Batch — A small subset of the dataset processed together at one time

Iteration — One parameter update (one batch processed)

Training Dataset Flow

01

Training data is divided into batches

02

Batches are processed one at a time

03

When all batches are processed, one epoch is complete

04

The cycle repeats for many epochs

What Is an Epoch?

An epoch is one complete pass through the entire training dataset.

Epoch Example

Training dataset: 1,000 examples

Batch size: 100

Batches per epoch: 10

One epoch — All 10 batches processed — model has seen all 1,000 examples once

Why Multiple Epochs?

Epoch Progress Example

Epoch 1 — Accuracy: 52%

Epoch 5 — Accuracy: 74%

Epoch 10 — Accuracy: 85%

Epoch 20 — Accuracy: 92%

A single pass is rarely enough — the model needs many exposures to learn stable patterns.

Too Few vs Too Many Epochs

Too Few (Underfitting)

Epoch 2: Training 61% | Validation 60%

The model has not had enough training time to learn meaningful patterns.

Too Many (Overfitting)

Epoch 99: Training 99% | Validation 72%

The model has memorized training examples rather than generalizing.

What Is a Batch?

A batch is a small subset of training data processed together before the model updates its parameters.

Batch Example

Dataset: 10,000 examples

Batch size: 100

Batches per epoch: 100

Why Batches
  • Processing the entire dataset at once may require too much memory
  • Updating after every single example causes unstable learning
  • Batches balance efficiency and update frequency

Common sizes — 16, 32, 64, 128, 256 (powers of 2 for GPU efficiency)

Small vs Large Batch Sizes

Small Batch (e.g., 10)
  • Lower memory requirement
  • More frequent updates per epoch
  • Can help escape local minima
  • Slower per epoch overall
  • Noisier gradient updates
Large Batch (e.g., 250)
  • Faster computation per update
  • More stable gradient estimates
  • Better use of GPU parallelism
  • Requires more memory
  • Fewer updates per epoch

Types of Batching

Full-Batch (Batch Gradient Descent)

Batch = entire dataset (e.g., 1,000 examples)

Very stable updates. May be too slow for large datasets.

Mini-Batch Gradient Descent

Batch = small subset (e.g., 100 examples)

Most commonly used in practice — balances stability and efficiency

Stochastic Gradient Descent (SGD)

Batch = 1 example at a time

Very noisy but can help escape local minima. Updates parameters 1,000 times per epoch if dataset has 1,000 examples.

What Is an Iteration?

An iteration is one parameter update — one time the model processes a batch and adjusts its weights.

Formula

Iterations per epoch = Dataset size / Batch size

Example — 2,000 examples / 100 batch size = 20 iterations per epoch

Total iterations — 20 × 10 epochs = 200 total iterations

Uneven Batches

Dataset: 1,050 examples | Batch size: 100

Result: 10 full batches of 100 + 1 partial batch of 50

Epoch, Batch, and Iteration — Comparison

ConceptDefinitionExample
EpochOne full pass through all training data10 epochs = data seen 10 times
BatchSubset of data processed togetherBatch size 100 from 1,000 = 10 batches
IterationOne parameter update (one batch)10 batches per epoch = 10 iterations per epoch

Loss Progression Across Iterations

Training Loss Over Time

Iteration 100 — Loss: 2.5 (many errors)

Iteration 500 — Loss: 1.2 (improving)

Iteration 1000 — Loss: 0.4 (nearly converged)

Good Training Loss

Training loss decreasing

Validation loss also decreasing

Both losses converge to a low value

Overfitting Loss Pattern

Training loss continues to decrease

Validation loss stops decreasing and rises

Growing gap indicates memorization

Early Stopping

Early Stopping Example

Epoch 5 — Validation loss: 0.50

Epoch 10 — Validation loss: 0.30 ← Best model saved here

Epoch 15 — Validation loss: 0.38 ← Getting worse

Stop training and use the Epoch 10 model

Data Shuffling

Why Shuffle Before Each Epoch
  • Prevents the model from learning patterns based on data order
  • Ensures each batch is representative of the full dataset
  • Helps the model generalize better

Real-World Examples

Image Classification

Dataset: 1,000 images | Batch size: 100 | Iterations per epoch: 10

50 epochs → 500 total iterations → Accuracy: 45% → 93%

Spam Detection

Dataset: 5,000 emails | Batch size: 50 | Epochs: 8 | Total iterations: 800

Validation F1 score: 0.62 → 0.91

Student Grade Prediction

Dataset: 2,400 records | Batch size: 120 | Epochs: 15 | Total iterations: 300

MAE decreases from 15.2 to 3.8

Choosing the Right Settings

Choosing Epochs

Too few — Both training and validation accuracy low (underfitting)

Too many — Training high, validation drops (overfitting)

Best approach — Use early stopping with validation loss monitoring

Choosing Batch Size
  • Limited by available GPU/RAM memory
  • Depends on dataset size and model architecture
  • Start with 32 or 64 as a good default

Common Mistakes

Mistakes to Avoid
  • Training for too many epochs without monitoring validation → Overfitting
  • Using a batch size too large, causing memory errors
  • Not shuffling data before each epoch
  • Using too small a batch size on large datasets → Very slow training
  • Assuming more iterations always mean better performance

Key Takeaways

Summary
  • An epoch is one full pass through the entire training dataset
  • A batch is a small subset of training data processed at one time
  • An iteration is one parameter update (one batch)
  • Iterations per epoch = Dataset size / Batch size
  • Too few epochs causes underfitting; too many causes overfitting
  • Use early stopping to automatically find the best number of epochs
  • Shuffle data before each epoch to prevent order-based learning
  • Mini-batch sizes of 32–256 are the most common in practice

Need Help?

Ask the AI if you need help understanding epochs, batches, iterations, how to choose batch sizes, early stopping, or how training progresses over time.