Bolts can loosen on their own when exposed to constant vibration, but there are ways to lock the bolt in place. One way is to use a washer, that disc of metal or rubber that sits under the bolt head against the surface of the spot where the bolt sits. Another option is to use a threadlocker, which is a liquid or paste that acts as an adhesive, effectively gluing the bolt in place. (Note that there are some brands of threadlocker that are so well-known that people sometimes automatically associate the term with a specific brand name, but "threadlocker" is technically the general term for the product.)
Being able to lock the bolt in place and not worry about extreme loosening due to vibration gives you peace of mind while operating the machinery that the bolt is in. But are washers better, or should you use a threadlocker?
How Vibration Loosens Bolts
First, you have to understand why this is happening. As machinery vibrates due to the motor, the housing where the bolt and nut are can make the bolt itself shake. If there are gaps between the threads on the bolt and the threads on the inside of the hole where the bolt is (and there usually are some), the bolt then has some room to move. The shaking from the vibrations eventually starts the bolt moving and turning a tiny bit. Over time, this tiny bit grows into enough to make the bolt loose. Special washers can lock the bolt in place, or you can glue it down. Threadlockers fill in those gaps and form an adhesive layer that wedges the bolt in place.
Permanent Installation Versus The Ability To Remove
One thing to remember is that these threadlocking liquids are strong adhesives. While you could eventually remove a bolt held in with a threadlocker, it will be very hard to remove. Threadlockers (liquid or paste) should be thought of as a permanent adhesive. So, if you need to be able to loosen the bolt manually on occasion, you'll want to use a washer to hold the bolt in and dampen vibration from machinery. Pay close attention to the condition of the washer every time you have to loosen the bolt, and replace the washer if it appears frayed (if rubber) or bent (if metal).
You'll encounter different types of threadlockers and washers. Feel free to contact a nuts and bolts supllier to find out which type is better for your machinery.