Rechargeable battery basics
Basic electrical concepts
If you are building a battery or wiring a bike, it is recommended that you are very familiar with the following basic electrical concepts. Also, you should understand Ohm's Law and its effect on voltage and current of parallel/series wiring. Electricity is dangerous- you need to understand how it works to avoid blowing up your bike or hurting yourself!
Most motors are rated using Watts (W), which is the maximum power output. Watts aren't often referred to for batteries, since two batteries with the same Watts can have very different characteristics.
However Watts are related to two very important factors for a battery: Watts = Volts * Amps. Therefore, for a given voltage, you should limit the current so that the Watts is not higher than the motor can handle.
A 36v e-bike will generally go 20mph (30 km/h), increasing the voltage will increase the top speed. However the law of diminishing returns applies (due to wind resistance, motor efficiency and other factors), so a 50% increase in voltage (eg 36v to 48v) may only increase top speed by 25%.
The voltage of a battery it not constant, it is higher when it is fully charged, and lower when it is discharged.  The nominal voltage is the average voltage while under load. Also, a battery's voltage will temporarily decrease when it is under heavy load, this is known as voltage sag.
To keep the battery within it's operating voltage range, a high voltage cutoff (HVC) and low voltage cutoff (LVC) is used. The HVC is part of the charging system (the battery charger or the BMS) and triggers when necessary to prevent the battery becoming overcharged. The LVC is fitted to the bike (the controller, BMS or e-bike computer) and shuts off the battery when necessary to prevent it becoming over-discharged.
You need to make sure the controller and motor can handle the maximum voltage your battery can supply.
For a 36 volt e-bike, increasing the maximum current from 20 Amps to 40 Amps will not usually increase top speed on flat roads (because the voltage is the same). But the 40A bike will climb a steeper hill.
To avoid damaging your battery or motor, you need to limit the current to not exceed what your battery or motor can handle.
Battery capacity is usually rated in Amp hours (Ah), see Wikipedia article on Amp hours). For example, A 10Ah battery can deliver 10 amps for 1 hour at its rated voltage. On its own, Amp hour isn't a useful measure, but Watt hours = Amp hours * volts. Therefore , you need to know the Ah to work out how far your bike can travel between charges.
Batteries are often rated in milliamp hours (mAh). 1000mAh = 1Ah
To increase the lifespan of the battery, it is best to not use the full capacity, but recharge when there is 20% remaining.
This is a measure of stored energy available, like the fuel tank size in a car. Therefore Watt hours (Wh) determines how far you can ride between recharges.
Watt hours = Volts x Amp hours
Watt hour per kilometer/mile
See also Factors affecting power usage.
This is your rate of energy consumption, like L/100km or mpg in a car. It depends on many factors such as efficiency of the bike, average speed, hills and how much you pedal. Wh/km = Wh / distance travelled
By estimating your Wh/km (or Wh/mi) and working out the longest distance you would like to ride, you can determine what capacity battery you need.
To avoid overloading your battery, you need to know the maximum current the battery can supply. The discharge C-rate is used to determine this: Amps = C-rate * Ah 
Different battery types have different C-rates. For example, to achieve 25A current:
- a 20C LiPo battery would need a capacity of 1.25Ah
- a 1C LiFePo4 battery would need a capacity of 25Ah
This determines how quickly you can charge your battery.
Like discharging, the formula is: Amps = C-rate * Ah
This means a battery rated for 1C charging will be charged in 1 hour, 2C is 30 minutes, etc. Do not assume the charging C-rate is the same as the discharge C-rate. Charging a battery slower will increase its lifespan.
All batteries should be charged in a safe area with supervision (eg stay in the same room as the battery while it is charging). You should also have a dry powder or CO2 fire extinguisher ready, in case things go wrong.
Mixing batteries with different C-rates
Packs with different series configurations (eg 5S, 6S, 10S) can be put together in series.
Battery configuration ("S" and "P")
Often, a single battery pack isn't sufficient to provide the power and/or range required for an e-bike. Therefore, multiple packs are combined in series and/or parallel to obtain the required performance. For example, the following configurations are possible if you have bought four packs of 4Ah 6S LiPo:
- Maximum speed: 24S1P. This setup would go very fast, but you would drain the battery quickly at this speed.
- Maximum range: 6S4P. Perhaps too slow to be usable, but range would be very good.
- In-between: 12S2P. The speed and range would be approximately halfway between the other two options.
To obtain the required voltage from LiPo, it is often necessary to connect multiple packs in series. This is known as the "series configuration", which is abbreviated to "S". To determine total voltage, multiply cell voltage by number of cells. For example, 4S = 4*3.7 V = 14.8 Volts
Connecting the + and - terminals the wrong way causes a large spark which can burn you. This is known as KFF (Kentucky Fried Fingers)!
Number of cells in parallel. Multiply cell capacity by cell number to get total capacity. For example, 2P with 2000mAh batteries = 2* 2000 = 4000mAh (4Ah). Packs should be connected in series first, then parallel.
Battery Management Systems
A Battery Management System (BMS) ensures that individual cell voltages remain balanced while charging and discharging.
Sometimes people refer to Battery Monitoring System as a BMS. This is just a system to check individual cell voltages, to inform you whether the individual cell voltages are balanced and within safe limits.