Use a similar wallboard to what’s there already. If it’s an older home, you may run across a wallboard that’s an unusual thickness - sometimes 1/8th of an inch thicker than what you can get now. You can sandwich a slice of thin plywood or other material behind your patch to bring everything flush with the existing surface.
Using a drywall saw, clean up the edges of your hole. Cut a patch out of drywall material that is slightly smaller than the hole - you want it to just set in there easily - it doesn’t have to be a tight fit. Using drywall screws, (not nails or any other type of screws) screw your patch to the stud. You want the patch well supported. Control your driver - you want the screwheads to just dimple in beneath the surface of the wallboard - they shouldn’t be proud of the surface or be too deep.
Using drywall mud (not spackle or caulk), fill the gaps and the screw divots. Scrape the surface smooth with a wide putty knife, and let it dry overnight. The mud will shrink. Come back the next day, sand the area, apply another coat. Let dry, sand and repeat. At this point, you should be ready for paint.
If you’re tiling, you don’t have to make the surface perfect, just one or two coats of mud should do the trick.