The USPTO is entirely self-supported. The fees collected support all that goes into the granting of patents and registering of trademarks. Periodically, the Office reviews the fees charged and costs incurred, and revises the fee schedule, with input from patent stakeholders.
The results of the most recent revision of patent fees were issued earlier this month, with an accompanying press release on November 14. More information on the changes and on fee setting and adjusting can be found here, and the current fee schedule for both patents and trademarks is here.