It's surprising to me that many people still don't validate their code before publishing. An HTML or XHTML document, whether created by hand or by some script or content management system, is a set of instructions to the web browser on what (and how) to display content.
By validating your code, you ensure that your page conforms to an accepted set of standards. There are a number of different specifications for HTML that you can choose from. The W3C has made a number of recommendations, but the two that are most important are HTML 4.01 and XHTML 1.0. Very roughly speaking, HTML 4.01 is the last non-XML based dialect still in broad use. XHTML, quoting the W3C, is a reformulation of HTML 4.01 in XML, and combines the strength of HTML 4 with the power of XML.
Further, there are actually three "flavours" of XHTML 1.0. You will likely want to be working with XHTML Transitional most of the time, because of its backwards support for older browsers.
Now that we've covered the specifications that we will be vaildating to, the next step is to actually run the code through a validation service. Again, the W3C Validation Service will be the first stop. Why validate? Search engines are built to understand standard web page codes. Any code that doesn't conform to the standard will only confuse search engines, and we want to make the job of understanding your pages as easy as possible for them. As well, validation often points out problem areas that you may miss if you only look at the visual representation of your page.