You have an idea or have invented something. You have put in a lot of effort and want to ensure that you can profit from your work. How can you do this?
If you invention contains a truly novel idea, then you can try to patent your invention. Patenting your invention means that no one else can build any product using the core idea in your invention without your permission. But patents are expensive to obtain, and many inventors simply decide not to patent their inventions. Filing a patent also requires you to reveal your idea to the world, in exchange for intellectual property protection. If you think this might give a competitor a deep insight which might cause you trouble later, you might even consider not patenting your idea and keeping your invention a trade secret. The flip side of course, is that you wouldn't be able to sue others if they found out your invention and copied it.
If you decide that you want to patent your invention, then what do you have to do?
First, I suggest carefully writing down a description of your invention. Putting things down on paper helps to organize your thoughts and clarify the core features of your invention.
Then do a search to see what prior art there is. You want to be sure that your invention is truly novel, and no one else has thought of it before. Perhaps only certain aspects of it are new, but that's fine too.
Next, you'll want to talk to a patent attorney to prepare a patent filing. Unless you are very sure of what you are doing, it is best to hire a patent attorney. A patent is a legal document, and your ability to enforce your intellectual property rights depends greatly on how your patent has been written.
Once your application is ready, you will file it with the Patent Office. Then it will be inspected by a patent examiner who will decide if all your claims are to be allowed, or if any need to be modified. You patent attorney can also help you negotiate this process. After the patent examination, and if some or all of your patent claims still stand, then the patent office will issue a patent to you.