We analyze the spin flip loss for ultracold neutrons in magnetic bottles of the type used in experiments aiming at a precise measurement of the neutron lifetime, extending the one-dimensional field model used previously by Steyerl et al. [Phys. Rev. C 86, 065501 (2012)PRVCAN0556-281310.1103/PhysRevC.86.065501] to two dimensions for cylindrical multipole fields. We also develop a general analysis applicable to three dimensions. Here we apply it to multipole fields and to the bowl-type field configuration used for the Los Alamos UCNτ experiment. In all cases considered the spin flip loss calculated exceeds the Majorana estimate by many orders of magnitude but can be suppressed sufficiently by applying a holding field of appropriate magnitude to allow high-precision neutron lifetime measurements, provided other possible sources of systematic error are under control.