Width or height that you set is actually just the dimension of the content area itself. Padding, border and margin don't belong to that dimension.
Example: Let say you make a box with 600px width and 400px height, then a padding of 20px in all direction, border of 5px and margin 10px all around, then the space that you need is:
Width needed = 600px (content) + 40px (padding) + 10px (border) + 20px (margin)
Height needed = I guess you knew