Large metal objects like submarines create variances in the Earth's magnetic field, which the Poseidon P-8 is tuned to thanks to a tailpiece called the Magnet Anomaly Detector (MAD).
Alternatively, the plane can drop sonobuoys (that's sonar buoys) from on high, allowing the crew inside to measure the sound propagation that surrounds these underwater units, just as a submarine or warship typically would. The P-8 can send out more than 100 of these yard-long sonobuoys in a single flight.
At the other end of the plane, the P-8 also sports optical and infrared sensors (the latter for heat detection) and a radar system.
In addition to its primary function as an intelligence-gathering aircraft - it was even used in efforts to find Malaysia Airlines flight MH370 - the P-8 Poseidon carries a few different payloads: cruise missiles, bombs, mines, and even torpedoes.
The Navy currently owns 13 of these, with plans to eventually own a stable of 117 units.