For some firearms, the manufacturer will tell you when it was made and shipped from their factory (often for a fee). This will typically only apply to expensive, limited edition, rare, old, or otherwise uncommon guns. If you are looking for the lineage on your recent Glock purchase, you are wasting your time. However, if you have an heirloom lever action .44-40, Weatherby, Moore, Holland and Holland, or Colt SAA, you may find some interesting information.
If you are trying to check the serial number of a gun to see if it is stolen, several states have a stolen gun database you can check online. You simply type in the serial and wait a couple of seconds and you will either see 'no record found' or 'stolen, please contact local law enforcement'. The database may or may not tell you more than that based on state laws and ordinances.
A good rule of thumb is: If the person you bought/acquired the gun may be a 'gang member' or you would not trust them with money...the gun may be stolen or might have been used in a crime.
Last note, if you have searched for history on a guns serial number and not found any records indicating it is stolen, the gun (if it came from a 'sketchy' source) may have been used in an unlawful shooting. The ONLY ways for this to be found out is to either have a fired bullet or expended shell casing examined by law enforcement investigators and to have their marks checked against a crime database. This may not be possible without you getting some funny looks from the local PD when you ask them to perform this task. They may or may not and they may charge you a fee (if they do it at all).
Beware, if you gun turns out to have been used in a crime, you may not get it back (or you will have it seized for the duration of the investigation). You may also find yourself being treated like a suspect until you are cleared or been able to point out the person who you acquired the gun from. Good luck with that.