Smaller than 1/2 inch, just fill it in with spackling or sheet rock mud.
Larger than 2 inches, use the method of a board behind the patch.
I'll show you the method that I use. I like to use joint compound rather than spackling, but that is a choice for you. The pictures don't show the actual sheetrock mud, just the method used.
Step 1: Make the Patch
Turn the patch over so that you see the back of it.
Use a drywall knife to cut a "tic-tac-toe" pattern on the back of the piece.
The center square should be larger than the hole you are repairing.
Bend the pieces away from you and remove each piece, leaving the center square intact.
Step 2: Fit the Patch to the Hole
Place it over the hole to repair and trace around the edges of the center piece.
Use a drywall knife and cut out the hole so that the patch fits into the hole.
Step 3: Finish
The corners can be rounded to make a smoother transition.
NOW FOR FINISHING IT
Use about an 8-inch drywall knife.
Remove the patch and spread a layer of mud a little larger than the whole patch.
Get some mud inside the hole along the edges.
Place the patch in place.
Spread mud over the top, squeezing out any excess mud that is under the paper of the patch.
Let dry overnight.
Sand and apply another coat, feathering out the edges.
Let dry overnight.
If needed, do a third coat and let dry overnight.
Finish the surface to match the rest of the wall.
METHOD TO MATCH WALL TEXTURE
Often I can match the wall texture with this method:
Mix some sheetrock mud with water in a bowl or cup.
It should be fairly watery.
Take a paint brush and dip in the mixture.
Flip it toward the wall. Stop it suddenly with your hand so that it sprays onto the wall.
Try different techniques. If you don't like it, wipe it off and try again.
Try different paint brushes (stiff or loose)
One way that often works is to hold the end of the brush handle with the bristles hanging down.
Swing it toward the wall and let it bump your hand so that it knocks some mud onto the wall.