<p>Let's say you want to do digit recognition (MNIST) and you have defined your architecture of the network (CNNs). Now, you can start feeding the images from the training data one by one to the network, get the prediction (till this step it's called as doing <em>inference</em>), compute the loss, compute the gradient, and then update the parameters of your network (i.e. <em>weights</em> and <em>biases</em>) and then proceed with the next image ... This way of training the model is sometimes called as <em>online learning</em>.</p>

<p>But, you want the training to be faster, the gradients to be less noisy, and also take advantage of the power of GPUs which are efficient at doing array operations (<em>nD-arrays</em> to be specific). So, what you instead do is feed in <strong>say 100 images at a time</strong> (the choice of this size is up to you (i.e. it's a <em>hyperparameter</em>) and depends on your problem too). For instance, take a look at the below picture, (Author: Martin Gorner)</p>

<p><a href="https://i.stack.imgur.com/8FzdQ.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8FzdQ.png" alt="Batch size of 100"></a></p>

<p>Here, since you're feeding in 100 images(<code>28x28</code>) at a time (instead of 1 as in the online training case), the <strong>batch size is 100</strong>. Oftentimes this is called as <em>mini-batch size</em> or simply <code>mini-batch</code>.</p>

<hr>

<p>Also the below picture: (Author: Martin Gorner)</p>

<p><a href="https://i.stack.imgur.com/vncAa.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vncAa.png" alt="batch size again"></a></p>

<p>Now, the matrix multiplication will all just work out perfectly fine and you will also be taking advantage of the highly optimized array operations and hence achieve faster <em>training</em> time.</p>

<p>If you observe the above picture, it doesn't matter that much whether you give 100 or 256 or 2048 or 10000 (<em>batch size</em>) images as long as it fits in the memory of your (GPU) hardware. You'll simply get that many predictions.</p>

<p>But, please keep in mind that this <em>batch size</em> influences the training time, the error that you achieve, the gradient shifts etc., There is no general rule of thumb as to which batch size works out best. Just try a few sizes and pick the one which works best for you. But try not to use large batch sizes since it will overfit the data. People commonly use mini-batch sizes of <code>32, 64, 128, 256, 512, 1024, 2048</code>.</p>

<hr>

<p><strong>Bonus</strong>: To get a good grasp of how crazy you can go with this batch size, please give this paper a read: <a href="https://arxiv.org/pdf/1404.5997.pdf" rel="noreferrer">weird trick for parallelizing CNNs</a></p>
What is a batch in TensorFlow?
<p>The introductory documentation, which I am reading (<a href="https://www.tensorflow.org/get_started/" rel="noreferrer">TOC here</a>) uses the term &quot;batch&quot; (<a href="https://www.tensorflow.org/tutorials/keras/classification" rel="noreferrer">for instance here</a>) without having defined it.</p>