Each battery is a source of electrical charge, Q \$(Q = i \ t)\$ hence the unit of capacity, mAh.
For simplification and ease of explanation, we can think of a battery as a capacitor. So we can write
$$
Q = C \ V
$$
where \$V\$ is the battery voltage in Volts and \$Q\$ is the battery capacity (charge) in milliamp-hours. As you use the battery, it'll get discharged (i.e. Q will decrease) therefore the voltage will decrease. Simple.
Now we can have a look at the combined capacity.
- Parallel Connection: You sum the capacitances when they are connected in parallel. So if you parallel the batteries, assuming \$V\$ is the same for all, we can write:
$$
C_{tot}=C_1+C_2+...C_N = \frac{Q_1}{V} + \frac{Q_2}{V} + ...+ \frac{Q_N}{V}\\
\Rightarrow Q_{tot}=Q_1+Q_2+...+Q_N
$$
So the capacities will be summed when the batteries are connected in parallel. For example, if you connect two 3.7V/3400mAh and one 3.7V/2000 mAh batteries in parallel, you'll have 3.7V/8800mAh.
- Series Connection: You inverse the sum of the inverse of the capacitances to find the equivalent capacitance. And also the voltages add up.
For simplicity, we start with an assumption of identical (i.e. equal voltage and capacity) batteries are connected in series. So we can write:
$$
C_{tot}=\Big(\frac{1}{C} + \frac{1}{C} + ... + \frac{1}{C}\Big)^{-1} = \frac{C}{N}\\
\Rightarrow Q_{tot}=C_{tot} \ V_{tot}=\frac{C}{N} \ (N \ V) = C \ V = Q
$$
So the total capacity stays the same, but the voltage increases so total energy increases.
One important point here is that the lowest capacity sets the total capacity when unequal-capacity batteries are connected in series. Because, since the battery voltage decreases as it discharges and therefore the lowest-capacity one will discharge quicker than the others, the decrease of the bank voltage will be more compared to that of the series-connected-identical-batteries. To remain the required voltage on a series connection, the lowest capacity is taken as total capacity.