The NYPD has a titanic problem.

Like the famed ocean liner of that name, the greatest police department in world history — as it likes to portray itself — seems headed toward an iceberg while the skipper, Mayor Bill de Blasio, seems oblivious to the dangers ahead. That iceberg is the investigation by U.S. Attorney Preet Bharara that has led to the transfers and retirements of 10 chiefs and inspectors.

So far, there have been two significant arrests. Borough Park resident Alex Lichtenstein was charged with bribing cops at the pistol license division, and Hamlet Peralta, a Harlem restaurant owner friendly with top brass, was indicted after allegedly bilking investors of $12 million. At least one top cop lost money, as did businessmen Jona Rechnitz and Jeremy Reichberg, both of whom allegedly bribed NYPD brass with gifts.

Two of those NYPD officials filed for retirement last week. A third, Deputy Chief John Sprague, is on modified assignment; his lawyer said he refused to cooperate with the feds.

Commissioner Bill Bratton had promoted Sprague just a few months ago, which tells you how close Bharara is playing his cards.

The word at 1 Police Plaza is that Bratton is allowing the top brass to retire without departmental charges. That would allow the officers to keep their pensions should indictments follow. Still, should any of them be convicted, Bharara could push for pension forfeiture as part of a penalty.

At a news conference last week, de Blasio said the process for the top brass retirements was appropriate. Asked how the scandal affected the NYPD, he said that it was not “stopping the men and women from making . . . arrests.”

The problem for everyone, probably Bharara included, is no one knows where the investigation will go. Prosecutors disclosed last week they have 30,000 emails from Peralta’s laptop and months of wiretaps. You can also bet that Peralta, Lichtenstein, Rechnitz and Reichberg are singing like jaybirds about their dealings with NYPD brass.

Remember that the Knapp Commission began with cop Frank Serpico making allegations about one NYPD plainclothes squad — his own.

The result? The commission discovered wholesale and systemic corruption right up to the commissioner’s office.