Proper calculation of padding