The good news about fixing the locking mechanism on your door knob is that minor problems are fairly simple to fix. The bad news is that often, the best way to fix more complex problems is to replace the internal mechanism; actually repairing the bolt mechanism requires expertise and specialized tools, making it less expensive to simply replace them outright. Diagnosing whether you need that kind of repair is actually the same process as repairing the minor problems that are within your reach.
Find the screws that hold your knob to the door, usually located on the inside face, behind the knob. Uncrew them using your screwdriver.
Pull the two knobs apart. This will remove them from the locking mechanism. If the knob is stuck to the door with paint, a sharp rap with the butt of your screwdriver should knock it free.
Pull the lock mechanism out of the end of the door.
Apply a short spray of WD-40 to the end of the locking mechanism--the part that's visible when the door is open. Apply another short spray to the opening in the mechanism where your door knob inserts. Wipe off excess with a rag.
Reinsert the lock mechanism into the edge of your door. The WD-40 on the end of the mechanism will help lubricate it if the mechanism was simply stuck.
Slide the doorknob through the opening in your mechanism and screw it back into place. In some cases, the knob will have gone offline inside the mechanism. Reassembling and lubricating this area will address both of these problems.
Screw the doorknobs back together using the screws and your screwdriver.