Analytical mathematical models and solutions for spatial localization of acoustic waves through an impedance discontinuity produced by an intermediate damped side branch are studied in stationary media in ducts with varying cross sections. Three specific geometries, namely, with polynomial, sinusoidal, and exponential longitudinal variations, are investigated. The sound fields inside the ducts are modeled by Webster's horn equation. Traveling-wave solutions are obtained by appropriate transformations. The side-branch impedances required for spatial localization (confinement) of traveling and standing waves are found analytically and verified numerically using three-dimensional finite element analysis. The impact of the longitudinal variation of the duct's cross-sectional area (CSA) on the side-branch impedance is examined. It was found that the required side-branch resistance changes more than the reactance with the variation of the duct CSA. A measure of a traveling wave is defined to quantitatively examine the spatial localization of acoustic waves. It was found that the CSA corrections on the side-branch impedances are important. The results of this study reveal the quantitative relationships between the side-branch impedance and the CSA variations for zero reflection from the impedance discontinuity. The mathematical approach presented is potentially helpful for a design of a full anechoic termination and energy localization in duct systems.