In this paper, we investigate the optimum way to allocate redundancy of finite-length nested codes for modern nonvolatile memories suffering from both permanent defects and transient errors (erasures or random errors). A nested coding approach such as partitioned codes can handle both permanent defects and transient errors by using two parts of redundancy: 1) redundancy to deal with permanent defects and 2) redundancy for transient errors. We consider two different channel models of the binary defect and erasure channel (BDEC) and the binary defect and symmetric channel (BDSC). The transient errors of the BDEC are erasures and the BDSC's transient errors are modeled by the binary symmetric channel, respectively. Asymptotically, the probability of recovery failure can converge to zero if the capacity region conditions of nested codes are satisfied. However, the probability of recovery failure of finite-length nested codes can be significantly variable for different redundancy allocations even though they all satisfy the capacity region conditions. Hence, we formulate the redundancy allocation problem of finite-length nested codes to minimize the recovery failure probability. We derive the upper bounds on the probability of recovery failure and use them to estimate the optimal redundancy allocation. Numerical results show that our estimated redundancy allocation matches well the optimal redundancy allocation.