How do the brain and nerves create electrical pulses?
This is quite a big question! I'll try to outline the basic view.

First, let's review how neurons signal between each other. The canonical way for a neuron to send a signal to a downstream neuron is by generating an action potential, the "electrical impulse" you have heard of. This action potential causes the release of neurotransmitter at a point where the two cells are very close to each other called a synapse. The downstream postsynaptic cell receives the neurotransmitter signal and converts it into a small electrical signal. If enough of these small electrical signals happen in a short time, they sum together and are likely to initiate an action potential in the second cell and the cycle repeats all along the circuit.

How is the electrical signal generated? The basics of how this works was worked out most famously by Hodgkin and Huxley in 1952. The short story is that the plasma membrane is selectively permeable to ions. Let's build the concept from the ground up.

The toolbox


Imagine a sphere of plasma membrane that represents a simple neuron. For starters, we assume that this membrane is bare lipid with no membrane-associated proteins. Because of the hydrophobicity of the bilayer, charged particles cannot diffuse through the membrane. 
The cell is bathed, inside and outside, in a solution containing many ions (charged atoms), including sodium (Na+), potassium (K+), chloride (Cl-), and calcium (Ca2+). As we noted above, these ions cannot go through the membrane without "help".
Now we add an ion pump protein into the membrane which will pump sodium ions out and potassium ions in. This particular pump, the Na-K ATPase, creates an excess of sodium ions outside the cell and an excess of potassium ions inside.
Now we add a potassium ion channel to the membrane. This protein creates a pore in the membrane that only allows potassium ions through. This particular protein's pore is always open. Now things start getting exciting...
What do the potassium ions do now that they can go through the membrane? Ions will move based on the forces created by their electrochemical gradients. The pump created a chemical gradient by putting excess K+ inside, so the K+ ions start to flow out through the ion channels. But K+ ions are positively charged, so when they flow out, positive charge starts building up outside and negative charge builds up inside. This electrical gradient opposes the chemical gradient, tending to pull the K+ ions into the cell while the chemical gradients pulls K+ ions out. The influx and efflux reach an equilibrium at the Nernst potential, where the electrical and chemical forces equal out. For physiological concentrations of K+ ions, the K+ equilibrium potential is about -80mV or -90mV. This means that K+ ions will flow until the outside of the cell is 80-90mV more positive than the inside of the cell. We started at 0mV, so K+ ions mostly flow out.
We now have a membrane potential, a difference in electrical potential between the inside and the outside of the cell at about -80mV (usually closer to -70mV or -60mV in "real life"). In particular, this membrane potential is the resting potential that exists when the cell is not active. We can simplify for now and think of the resting potential as being set by a resting permeability of the membrane to potassium ions, but not to sodium ions. We call this membrane polarized, and thus depolarization is when the membrane potential becomes more positive, and hyperpolarization is when the membrane potential becomes more negative.
Now, we add to the membrane a voltage-gated sodium channel, an ion channel that passes only sodium ions but is usually closed. The voltage-gating means that this ion channel is sensitive to the membrane potential. At the resting potential, the pore is closed and the membrane is still impermeable to sodium ions. When the membrane potential becomes slightly more positive, the channels opens and sodium ions can flow. This channel is also inactivating, so that when it opens it only opens for a short period of time, letting in a limited amount of sodium.
What way will sodium flow when we open this channel? Because of the negative resting potential (-70mV) and the excess of sodium ions outside due to the pump, both the electrical and chemical gradient will drive sodium ions into the cell. The sodium equilibrium potential is usually around +60mV.
To complete the machinery for generating an action potential, we also add a voltage-gated potassium channel to the membrane. It works just like the voltage-gated sodium channel that is also closed at rest and opens when the membrane potential becomes more positive. This channel opens a bit more slowly than the sodium channel does, but it does not inactivate.


Generating an action potential

Ok, so how do these parts come together to create an electrical impulse?


The cell sits at its resting membrane potential, with all of its voltage-gated channels closed. It receives a signal from an upstream cell that causes a slight depolarization. The action potential will initiate when the membrane potential hits the threshold potential. 
At the threshold potential, the voltage-gated sodium channels open letting sodium ions flow into the cell. The sodium flux pulls the membrane from the resting potential (-70mV) towards the sodium equilibrium potential (+60mV). These values are far apart, so the driving force is large and the membrane depolarizes rapidly. This is the action potential upstroke.
The depolarization also activates the (slightly slower) voltage-gated potassium channels. The potassium ions flow out and drive the depolarized membrane (about +20mV at the action potential peak) back towards the potassium equilibrium potential (-80mV). At the same time, the sodium channels are inactivating so that sodium is no longer depolarizing the membrane. The repolarization rate is usually slower than the depolarization rate. This is the action potential downstroke.
The whole process of the action potential depolarization/repolarization cycle takes about 2-3 milliseconds in an "average" neuron. Once the cell reaches resting potentials again, the membrane is basically reset. The voltage-gated channels are turned off. The ion pump moves the potassium ions that flowed out and the sodium ions that flowed in. That patch of membrane is ready to fire another action potential!


As a final note, I'll mention that the voltage-gated sodium channel provides a mechanism for the action potential to propagate down the axon. The action potential is initiated in one location of the cell, and creates a depolarization. This depolarization causes the voltage-gated sodium channels in neighbouring regions of the membrane to open and generate an action potential cycle of their own. This is how an action potential travel down axons (and sometimes dendrites too).