A nut is a type of hardware fastener with a threaded hole. Nuts are almost always used opposite a mating bolt to fasten a stack of parts together. The two partners are kept together by a combination of their threads' friction, a slight stretch of the bolt, and compression of the parts. In applications where vibration or rotation may work a nut loose, various locking mechanisms may be employed: Adhesives, safety pins or lockwire, nylon inserts, or slightly oval-shaped threads. The most common shape is hexagonal, for similar reasons as the bolt head - 6 sides give a good granularity of angles for a tool to approach from (good in tight spots), but more (and smaller) corners would be vulnerable to being rounded off. Other specialized shapes exist for certain needs, such as wing nuts for finger adjustment and captive nuts for inaccessible areas.
Nuts are graded with strength ratings compatible with their respective bolts; for example, an ISO property class 10 nut will be able to support the bolt proof strength load of an ISO property class 10.9 bolt without stripping. Likewise, an SAE class 5 nut can support the proof load of an SAE class 5 bolt, and so on.