Abstract Interest in aircraft electrification and hydrogen fuel cells is driving demand for efficient waste heat management systems. Ultimately, most of the heat must be rejected to the freestream air. Ducted heat exchangers, also called ducted radiators, are the most common and effective way to do this. Engineers manually design ducted heat exchangers by adjusting the duct's shape and heat exchanger's configuration to reduce drag and transfer sufficient heat. This manual approach misses potential performance improvements because engineers cannot simultaneously consider all of the complex interactions between the detailed duct shape, heat exchanger design, and operating conditions. To find these potential gains, we apply gradient-based optimization to a three-dimensional ducted heat exchanger computational fluid dynamics (CFD) model. The optimizer determines the duct shape, heat exchanger size, heater exchanger channel geometry, and coolant flowrate that minimize the ducted heat exchanger's power requirements while rejecting enough heat. Gradient-based optimization enables the use of nearly 100 shape design variables, creating a large design space and allowing fine-tuning of the optimal design. When applied to an arbitrary, poorly performing baseline, our method produces a nuanced and sophisticated ducted heat exchanger design with five times less cruise drag. Employing this method in the design of electric and fuel cell aircraft thermal management could uncover performance not achievable with manual design practices.