A line or 2 of glue on the surface of the carpet pad will often be sufficient.
Replace section of carpet pad.
If carpet tape is not doing the job you can also use carpet glue to hold the patch in position.
If you are only replacing a 6x9 foot area with no seams i would likely just replace the carpet and pad if i could find a usable pattern on roll at lowes or home depot or a remnant at a dealer.
Remove the old carpet pad.
If a section of your floor covering has seen better days remember that you can patch carpet saving the considerable cost of replacing the entire thing.
How to install carpet on stairs hard is it you carpet maintenance tips 3 quick fi family handyman how to install carpet like a pro easy floor remodeling how to install wall carpet yourself tos diy signs you need new carpet padding georgia finishers inc how to install wall carpet icreatables.
Using a razor knife cut around the section of padding you are removing so you can pull it away from the rest of the padding.
Keep in mind that if you plan on replacing the carpet the patch will adhere to the padding making it harder to salvage the pad.