Sticking Locks and Doorknobs
If the knob/bolt is easy to operate with the door open, then there's probably an interference/misalignment with the hole in the door jam (wall) that the latch/bolt goes into. (This hole is called a strike recess and the metal cover called a strike plate.)
If the knob/bolt is hard to operate with the door open and has been since the lock was installed, it may have been installed too tight. Loosen the screws slightly and see if it helps. [Try here if you can't find the screws.]
If it's not one of the above, spray "Tri-Flow," a spray lubricant with Teflon, into the keyhole. (See other lubricants below.) Depress the spring latch-bolt and spray into it, or extend a deadbolt and spray it and the crack around where it comes out of the door. If it's outdoors and frozen--thaw it first (hair dryer?).
If this doesn't fix it, carefully take off a cover plate on one side of the lock and spray the innards.
Still no luck? Remove the entire lock from the door. You'll probably have to remove a couple of screws on the edge of the door to remove the bolt. [You'll want to pick a time to do this when you can recover if you can't get the lock back in and working.] If the lock seems to work smoothly while removed, the hole for the bolt (the small hole/tunnel in the door going from the big hole to the edge of the door.) may have been drilled wrong--too small, at an angle, etc.
If none of this works the lock is probably defective.
If you replace it, that well known consumer product rating magazine rates National and MasterLock (I've about concluded Master has quit making deadbolts and locksets.) best deadbolt and Schlage best for other styles, such as entry locksets, etc.
NOTE: Graphite should be used sparingly. Too much, or repeated use, can build-up inside and
foul the lock.
If you have to relocate the strike plate Mr. Fixit has this advice:
From: "Mr Fixit" <email@example.com>
You will need to determine where the bolt is rubbing and adjust the strikeplate (in the jamb). And possibly chisel the hole on one side or top or bottom to clear the way for the bolt to slide in freely.
You may find yourself trying to move the plate screws 1/2 hole-space or less and the screws will want to go back into the original holes. Get some round toothpicks and wood glue. Pack the original holes with these and drive the last one in. This may sound hokie, but round toothpicks are made of harder wood than your door jamb is.
More on Lubes
Subject: Re: WD-40....
WD40, in reasonable amounts, is safe. Graphite, in reasonable amounts, is safe. It's significantly easier to overdo graphite and create a problem than to overdo WD40. On the other hand, WD40 is not really a lubricant per se. On the third hand there are yet other alternatives, such as Tri-Flow, which combine the advantages of both.
What you _really_ shouldn't do is use any variety of oil ... on a lock unless you know ___EXACTLY___ what you're doing. Most of those are _not_ safe.
If you take it apart, a *small amount* of white lithium grease is an excellent lubricant.