๐Ÿ”ฅLimited Offer: Get 50% OFFon AI & Full Stack Courses๐Ÿ”ฅ
Back to Deep Learning Notes
Topic #121

Epoch, Batch, Iteration

These three terms โ€” epoch, batch, and iteration โ€” describe training at different levels of granularity, and beginners frequently mix them up in ways that make training logs and progress bars confusing to interpret correctly.

Definitions

TermDefinition
Batch (mini-batch)A subset of the training data used for one weight update (see Mini-Batch Gradient Descent)
Batch sizeThe number of examples in one batch (e.g. 32, 64, 128)
Iteration (step)One weight update โ€” processing exactly one batch through forward pass, backward pass, and optimizer step
EpochOne complete pass through the entire training dataset โ€” many iterations make up one epoch

The Relationship, as a Formula

\[ \text{iterations per epoch} = \left\lceil \frac{\text{number of training examples}}{\text{batch size}} \right\rceil \]

The ceiling function accounts for the last, possibly smaller, batch when the dataset size isn't evenly divisible by the batch size.

Numerical Example

A training set has 50,000 examples, batch size is 128:

\[ \text{iterations per epoch} = \left\lceil \frac{50000}{128} \right\rceil = \lceil 390.625 \rceil = 391 \]

Training for 20 epochs means \(391 \times 20 = 7{,}820\) total weight updates (iterations) โ€” this is the number that actually matters for a learning rate schedule defined in terms of steps, like One Cycle Learning Rate.

Code โ€” Seeing the Counts Directly

from torch.utils.data import DataLoader

dataset_size = 50000
batch_size = 128
loader = DataLoader(range(dataset_size), batch_size=batch_size)

print(len(loader))   # 391 -- this IS "iterations per epoch"

num_epochs = 20
total_iterations = len(loader) * num_epochs
print(total_iterations)   # 7820 -- total weight updates across the whole training run

Where Each Term Shows Up in Practice

  • A learning rate schedule like StepLR (see Step Decay) is typically stepped once per epoch.
  • A schedule like OneCycleLR is typically stepped once per iteration (batch), since its phases are defined relative to total training steps.
  • Training logs commonly report loss both per-iteration (noisy, immediate feedback) and averaged per-epoch (smoother, higher-level trend).

Common Mistakes

  • Confusing "iteration" with "epoch" when reading someone else's training configuration โ€” a learning rate schedule or logging interval specified "per step" behaves very differently from one specified "per epoch," and mixing them up silently misconfigures training.
  • Assuming batch size doesn't affect how many total iterations a fixed number of epochs represents โ€” a larger batch size means fewer iterations per epoch (and total), which affects how frequently step-based schedules like One Cycle actually adjust the learning rate.

Interview Relevance

Q: "If you double the batch size without changing the number of epochs, what happens to the total number of weight updates?" It roughly halves โ€” since each batch now covers twice as many examples, half as many batches (iterations) are needed to complete one epoch, and therefore half as many total weight updates occur across the same number of epochs. This is part of why learning rate is often scaled up when increasing batch size (see Learning Rate).

Practice Question

A dataset has 12,800 examples and batch size is 256. How many iterations are in one epoch? How many total iterations occur across 15 epochs?

Want to go beyond the notes?

Join CodingNow 2.0's Deep Learning course โ€” live mentorship, real projects, and 100% placement support.

Enroll Now โ€” Free Demo Available

Epoch, Batch, Iteration โ€“ FAQs

Quick answers about learning Epoch, Batch, Iteration in Deep Learning.

This free note from CodingNow 2.0 explains Epoch, Batch, Iteration in Deep Learning โ€” concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Deep Learning topic on CodingNow 2.0, including Epoch, Batch, Iteration, is 100% free with no signup required.
With focused practice, most students grasp Epoch, Batch, Iteration in 1โ€“3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) โ€” expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now