Batch Size Calculator
Two Sides of the Same Division
Batch size and step count are locked together by the size of the dataset — pick one and the other follows. This calculator handles both directions: working out the batch size needed to hit a target number of batches, or working out how many optimizer steps a chosen batch size produces per epoch.
The Formulas
Find Batch Size: Batch Size = Dataset Size / Number of Batches (rounded up)
Find Steps per Epoch: Steps per Epoch = ceil(Dataset Size / Batch Size)
Find Steps per Epoch: Steps per Epoch = ceil(Dataset Size / Batch Size)
Worked Examples
| Mode | Input | Calculation | Result |
|---|---|---|---|
| Find Batch Size | 1,700 desired batches | 60,000 / 1,700 = 35.29, rounded up | 36 samples per batch |
| Find Steps per Epoch | Batch size 64 | ceil(60,000 / 64) = ceil(937.5) | 938 steps per epoch |
Rounding up matters in both directions: a batch size rounded down would leave some batches oversized, and steps-per-epoch is always rounded up so the final, smaller batch still gets counted as a full step.
Where This Matters
- Matching a target step count — some training recipes specify a total number of optimizer steps rather than epochs; this calculator converts that into the batch size needed.
- Estimating training time — steps per epoch, multiplied by time per step, gives the epoch duration used elsewhere in training-time planning.
- GPU memory trade-offs — larger batch sizes use more memory per step but need fewer steps per epoch; this calculator makes that trade-off concrete.
How to Use This Calculator
- Choose the mode: Find Batch Size or Find Steps per Epoch.
- For Find Batch Size: enter Dataset Size and Desired Number of Batches.
- For Find Steps per Epoch: enter Dataset Size and Batch Size.
- Select Calculate to see the result.
Related Calculations
Feed the resulting batch size into the Epoch Time Calculator, or check its memory impact with the GPU Memory Calculator.