It's basically software that keeps track of what you are doing. One of the ways it works is through what are called "tracking cookies". The obvious question is "what is a cookie"? Aside from being a tasty snack, a cookie is a file that keeps track of your user preferences while you are visiting Web sites. For example, if you go to Amazon and add something to your shopping cart, the shopping cart is done through a cookie. Likewise, if you go to sites such as Mapquest and save an address, that is also done through a cookie. When you click on "Remember my username" on many sites, that is also done through a cookie.
In summation, cookies don't necessarily HAVE to be bad things.
However, cookies can be used for bad purposes. For example, I can keep track of your browsing preferences. If I see you are clicking on ads for certain types of cars, I might pop up more car advertisements, than, say, shoes.
A more diabolical version could be used for hacking. If you visit this Web site, I can see things such as your computer's IP address, your Web browser, and other such things. Someone who actually tried could possibly hunt down and save information such as email addresses. This information, when put together, could be used for hacking and other sorts of bad things.
There are no perfect solutions out there, but one of the free things you can do to protect yourself against spyware such as tracking cookies is to download an anti-spyware tool. The one I recommend is Lavasoft's Ad-Aware. After you install it, make sure you select "Full scan" instead of the "Smart scan", especially the first time you are running it.
Ad-aware can be downloaded from Lavasoft's Web site (make sure to get the "free" version):