For the purposes of this document, threads are expressly the "...prominent part of the spiral of a screw or nut". Threads have certain characteristics such as thread length and angle, which are collectively known as the "thread form". There are hundreds of thread forms commonly in use today, which have different purposes, advantages, and disadvantages.
The act of causing a piece of cylindrical (or conical) material, or a hole in a piece of material, to take on a thread by the removal of material is called "cutting threads", so named because you are removing material. This process is primarily used for metal parts, while plastic parts are generally molded - with the exception of threaded holes which are often tapped. It is possible to mold threads, but they must be of a certain minimum size, and they are generally somewhat imprecise due to realities of the plastic molding process. Molding threads is adequate for such products as soda and water bottles, and machining would not be practical on such a scale in any event. However, molding threads is inappropriate where any level of significant precision is required.
This brings us to the first method for cutting threads, the use of a tap and/or a die. A tap is essentially a tapered cylinder with small cutting surfaces on it, which cut away material much like a knife. It is used to thread holes. A die is a short cylinder with a hole through it, and the hole features the cutting surfaces; it is used to thread cylinders. Essentially, a tap is inserted straight into the hole and turned, and a die is brought perpendicular to the cylinder to be externally threaded, and then "screwed" onto it, thus cutting away material, and making threads. There are also self-tapping screws which are frequently used to tap a hole in plastic and fasten something to the plastic part (usually another plastic part) at the same time.
The use of tap and die has the advantage that it requires very little equipment and is easily done by anyone. The disadvantage is that it is not very precise or consistent as compared to the next method, machining.
Machining a thread is done on a lathe. There are lathes designed specifically for threading, but it can easily be done on a general-purpose lathe. The lathe's compound rest is rotated to the thread angle, and a threading tool is used. For an American Standard thread, for example, this tool has a 60 degree angle (the same angle as the thread) and a very slightly beveled nose. The lathe has a system by which it can feed the cross-slide toward the lathe's head stock (where the gearing resides) at specified rates, so you can set the feed rate to a given number of threads per inch. Then one simply engages the half-nut lever at the appropriate time, and makes successive passes, deeper into the stock each time, though each pass is individually shallower than the last. If one makes deep cuts at the end, the thread is easily damaged. Internal and external threads are made in essentially identical fashion. Forward and reverse threads are both cut with the lathe turning in the same direction, but for a forward thread one starts cutting the thread at the end of the stock, and for reverse one starts cutting at the inside, and cuts to the end.
Machining threads on a lathe has the disadvantage that is is generally much slower than using tap or die, and of course it requires a lathe, which is generally a costly piece of equipment to purchase, and often to maintain and operate. However, it has the advantage that any size and shape of thread may be made, including arbitrary sizes for which no tap or die exists. If one needs to make a nut to fit a bolt, or vice versa, one can start with an approximation of size, and simply machine the nut or bolt until it fits.
There are also ways to combine these methods, such as using the lathe to turn your stock, while using the lathe's end rest to advance a tool containing a die or a tap. While this often requires the production of additional tooling, it can often improve production speed dramatically.