It mostly pays for operating the patent office.
Patent offices don’t collect anywhere as near as trillions of dollars. For example, the [US patent office’s budget for 2023](https://www.commerce.gov/sites/default/files/2022-03/FY2023-USPTO-Congressional-Budget-Submission.pdf) estimates $4.25 billion in collected fees, and $4.15 billion in spending. The rest of the revenue is reserved.
Latest Answers