main padding calculation