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.
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 of 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. visit us today on njlocksmith247.com or call us 1-888-990-9980 we can help you with your problem lock.