In machine learning, a batch is a subset of training data used to update a model's parameters during training. Rather than processing one example at a time (which is slow) or all examples simultaneously (which requires too much memory), practitioners divide the full dataset into smaller groups called batches and train on each batch sequentially.
When training a neural network, each batch flows through the model, produces predictions, calculates loss, and triggers a backward pass that adjusts weights. This cycle repeats for each batch until all data has been processed once—this full cycle is called an epoch.
Batch size, the number of examples per batch, is a key hyperparameter. Small batches (8–32 examples) add noise to each update, which can help escape shallow local minima but makes training less stable. Large batches (256–2048 examples) produce more stable gradient estimates and train faster on modern hardware, but may converge to sharper minima. Medium batch sizes often balance these tradeoffs.
Batching serves multiple purposes: it enables efficient computation on GPUs (which parallelize well across examples), reduces memory requirements compared to full-dataset training, and introduces regularization through gradient noise. Many optimizers like SGD (stochastic gradient descent) and Adam inherently work with batches, updating parameters based on batch gradients rather than individual examples. The term "stochastic" in SGD refers to the randomness introduced by sampling batches rather than using the full dataset for each update.