Bobbers offer two main advantages. First, they keep your baited hook near the surface of the water. So if you're fishing a lake (for example), your baited hook typically hangs below the bobber the length of your leader. Generally speaking, most trout leaders used in spin fishing is 18-24 inches in length. So if using a bobber while lake fishing, you're typically fishing 18-24 inches below the surface.
Another advantage of fishing with bobbers is that they serve as a strike indicator. When the bobber dips below the water's surface, it's usually means a fish is checking out your bait and this is the time to set the hook.
Bobbers can be used when fishing in lakes and streams too (even though these bodies of water are usually much shallower than lakes).
Bobbers come in various sizes and colors. The smaller the bobber, the easier it will be for a fish to pull it under the water when it strikes (so it disappears from your sight). When fishing for smaller fish, smaller bobbers are preferred because because they don't interfere with a fish strike as much.
There are a few different different ways to rig a bobber on your rod and some of this depends on the type of bobber used (used stationary bobber, slip bobber, etc.).
Below are some videos you may find helpful.
Slip bobbers offer the advantage of making it easier to adjust the depth of your hook.