Cerebrospinal fluid (CSF) bathes and protects the central nervous system (the brain and the spinal cord). "Cerebro" means "brain"; "spinal" is a short version of "spinal cord"; and fluid is a liquid.

CSF is made by networks of blood vessels called choriod plexuses in each of the brain's four ventricles.

CSF flows through the subarachnoid space – the space between the two layers of meninges that are closest to the brain (the arachnoid layer and the pia mater). CSF also fills the brain's ventricles, and flows down the middle of the spinal cord (the central canal).

Contents
CSF is created from blood plasma (the liquid part of blood), so CSF's contents are very similar to plasma's.  CSF is 99% water.  It carries:
 Protein (though much less than plasma carries)
 Glucose (sugar)
 Nutrients
 Neurotransmitters (chemical messengers)
 Electrolytes (salts), like sodium, potassium, calcium, magnesium, and chloride.

There should be very few white blood cells in the CSF, or none at all.  There should be no red blood cells in the CSF.

What CSF does

CSF helps the brain float
Being surrounded by CSF helps the brain float inside the skull, like a buoy in water.  Because the brain is surrounded by fluid, it floats like it weighs only 2% of what it really does.  If the brain did not have CSF to float in, it would sit on the bottom of the skull.  The brain's weight would push the bottom of the brain against the skull.  Blood would not be able to get to the bottom of the brain because the blood vessels would be getting crushed by the weight of the brain on top of them.  Without getting blood (and the oxygen it carries), the neurons in the bottom of the brain would die.

CSF is the brain's cushion
CSF protects the brain by acting like a cushion.  Without CSF, every time a person moved their head, their brain would hit the inside of their skull.  This could injure the brain.  

When a person hits their head, CSF acts like the airbag in a car and can sometimes keep the brain from slamming into the inside of the skull.  However, when a person hits their head very hard – in a car accident, for example – the CSF cannot protect the brain from hitting the skull.  This can cause concussions, bleeding in the brain, brain damage, or even death.

CSF rinses toxins out of the brain

The brain's cells do chemical reactions to change one chemical to another chemical that the brain needs.  Sometimes, after a chemical reaction, chemicals that the brain does not need are left over.  These chemicals are called "waste products."  For example, when the brain's cells use oxygen and glucose (sugar) to create energy, carbon dioxide (CO2) is left over.  Too much carbon dioxide can poison the brain.

To keep waste products from building up in the CSF, the choroid plexuses make new CSF about four times a day.  The old CSF drains out into the bloodstream, bringing waste products and toxins with it.  In this way, the CSF rinses things that could hurt the brain out into the bloodstream.  The bloodstream can then carry these chemicals to organs that can get rid of them, like the kidneys and the lungs.  For example, the bloodstream carries carbon dioxide to the lungs, where it can be breathed out.

Testing CSF
Doctors can use samples of CSF to find out if a person has a brain infection, like meningitis, encephalitis, or syphilis.  CSF samples can also show bleeding from certain parts of the brain.  Swelling in the brain, caused by some inflammatory diseases like multiple sclerosis, can show in a CSF sample as well.

Usually, doctors take samples of CSF by doing a lumbar puncture (spinal tap).

Results
Normal CSF should be clear and colorless, with no red blood cells, and very few white blood cells.

Signs of a brain infection include:
 CSF that is cloudy, yellow, or pink
 More protein in the CSF than normal
 More white blood cells in the CSF than normal
 Less glucose (sugar) in the CSF than normal
 Bacteria, viruses, fungi, or other pathogens in the CSF

Protein levels that are higher than normal can be a sign of inflammation in the brain.  However, they can also be a sign of other problems, like a bleed in the brain; a brain tumor; epilepsy; and "acute alcoholism."

Cancer cells in the CSF are a sign that a person has brain cancer, or has cancer that started somewhere else and spread to the brain.

Problems with CSF

Too much
Head injuries and some diseases can make too much CSF build up in the brain.  This is called hydrocephalus.  The extra fluid puts pressure on (squeezes) the brain.  This is called increased intracranial pressure.  If the pressure gets high enough, the brain's blood vessels get crushed, and blood cannot get to the brain.  If a person's brain does not get enough blood and oxygen, they will become unconscious and their brain cells will die.  Eventually, the person will die.

Without treatment, 6 out of every 10 people with hydrocephalus will die.  The rest will have physical disabilities, intellectual disabilities, and/or other brain problems.

Not enough

Some problems can cause CSF to leak out through a hole or tear in the dura mater (the layer of the meninges that is next to the skull and the bones of the spinal cord).  CSF leaks are usually a complication of a lumbar puncture or certain kinds of surgery on the head, neck, or brain.  However, an injury to the head or spine can also cause a CSF leak.  Sometimes, doctors cannot find a cause for a CSF leak.

Most people with CSF leaks get better on their own, after the hole in the dura mater heals.  However, some CSF leaks can cause serious complications:
 Bacteria, viruses, or other pathogens can get in through the same hole CSF is leaking out of.  This can cause brain infections like meningitis.
 Without enough CSF to float in, the brain sits on the bottom of the skull.  The brain's weight can: 
 Crush the blood vessels in the bottom of the brain
 Press on the brainstem, causing very low blood pressure
 Push the brain down through the hole in the bottom of the skull, where the brainstem turns into the spinal cord.  This can cause paralysis, brain damage, coma, and death.

Related pages
 Central nervous system
 Brain
 Spinal cord
 Meninges

References

Anatomy of the nervous system
Brain