The front side of cabinets do not always fit against the wall without a gap. Fortunately, they are built with face frames that overlap the cabinet box about 1/4 inch, which can be sanded or planed to fit the wall. Cabinets without face frames use filler strips to make room for scribing. Removing the gap is called scribing the cabinet. You may be tempted to caulk the gap, but scribing the cabinet is much better looking and elevates the quality of your work. A pencil iwill do, but an inexpensive scribe tool works best when the gap is wider than 3/16 of an inch.
Apply masking tap along the edge to be scribed so that you can see the line you are about to draw.
Level or plumb your cabinet. Level a base cabinet by placing shims underneath it. To plumb a wall cabinet, hold it against the wall and place a shim between the wall and the face frame. A helper comes in handy while working with wall cabinets.
Hold your pencil flat against the wall and slide it along the face frame of the cabinet. If the gap is wider than 3/16 of an inch, use a scribe tool or hold your pencil in a way that maintains a consistent distance from the wall.
Sand the face frame or filler strip with a belt sander or block plane. To keep the back side of the face frame from hitting the wall, back bevel it a few degrees.
Place your cabinet against the wall and level or plumb it. If the gap is gone, you are done. If not, scribe it again and sand it to fit.
A scribe tool is simply a compass with only a wing nut. A regular compass has parts that make it difficult to get close to the wall. When removing more material than is easily done with a belt sander, use a block plane or power planer to remove most of the material and sand to your line with your belt sander. Box cabinets without face frames require a filler strip, not only to fit the cabinet to the wall but often to bring the cabinet away from the wall to clear door casings, baseboard or other obstacles.