Sodium chloride crystals are shaped like cubes because they are very tightly packed in together. Both sodium and chlorine are very reactive atoms, when they combine the sodium atom gives up an electron, and the chlorine atom catches it.
The connection turns both sodium and chlorine into electrically charged atoms called ions. The sodium ion has a positive charge, and the chlorine ion has a negative charge. The resulting molecule is called an ionic compound, with each negative charge attracting each positive charge. The ions bond very tightly in a repeating arrangement. This leads to the formation of a sodium chloride crystal that looks like a cube.