Cocaine molecules alter the communication between the brain cells (neurons) in certain brain regions. This communication is mediated by chemical messengers known as neurotransmitters.
Cocaine acts as a stimulant to these communications, causing some brain regions to become overactive. This process is described in more detail in the animation Drugs and the Brain.
The brain becomes habituated to this overactive communication. In time, it slows down its functioning to accommodate it. Without cocaine, the user then begins to feel tired and depressed, and longs for the effects of cocaine. This is cocaine addiction.