A patent is a right, granted by the Patent Office, enforceable in a court of law to prevent others, without the owner of the patent's permission, carrying out the invention defined by the wording of the patent. If the invention has been published in print or otherwise made available to the public, e.g. by demonstration or use in public, before the patent is applied for, then the patent right cannot be validly granted. The validity of the right can be challenged after grant. Basically, an invention is simply something new, something which has never been thought up before and which is not obvious. However, not every new idea, however ingenious, can be patented.
Most inventions are new machines, products or industrial processes.
These can generally be patented. Scientific theories and discoveries are not themselves patentable, though their application in industry may well produce inventions which are. The basis of the patent system is the grant of a patent in return for the disclosure of the invention. Disclosure in this context means telling the public, in practice the Patent Office which grants the patent, something not previously known or used. You must therefore file your patent application before the invention becomes publicly known, even before you yourself publicise it in any way at all.