The United Kingdom Patent Office states that the first patent was issued in London in the fifteen century. In the United States, the first patent was granted in 1790.
After inventing a work, the inventor must apply for and obtain a patent from the US Patent and Trademark Office in Washington, DC.
In order to patent something, you should have a patent attorney, licensed to practice before the Patent Office, assist you with the application. Upon receipt of your application, the Patent Office will examine your application to determine if it meets the legal requirements for obtaining a patent. The requirements are extremely complex, but simplified are that your invention is:
If granted, you receive a 20 year monopoly on selling, using, making or importing the invention in or into the United States; what is granted is not the right to make, use, offer for sale, sell or import, but the right to exclude others from making, using, offering for sale, selling or importing the invention.
You should be aware of two risks. First is that obtaining a patent can be expensive. You should consult your patent attorney to get a specific estimate, but the application and granting process can take years and require substantial legal work. Secondly, be aware that in exchange for your patent rights, your patent (ie how the invention works), becomes public information so that others may learn from your ideas and create further. Due to the disclosure result, many often opt not to seek patent rights so that they can keep their invention and ideas secret.