Most LEGO pieces have two basic components - studs on top and tubes on the inside. A brick's studs are slightly bigger than the space between the tubes and the walls. When you press the bricks together, the studs push the walls out and the tubes in. The material is resilient and wants to hold its original shape, so the walls and tubes press back against the studs. All of the basic LEGO elements use this principle to stick together.