The rank structure of officers in the NYPD is as follows (see this link for badges of the different ranks):
Police Officer
Detective (see below)
Sergeant
Lieutenant
Captain
Deputy Inspector
Inspector
Deputy Chief (1 star)
Assistant Chief (2 star)
Super-Chief [Chief of ___] (3 star)
Chief of Department (4 star)
Above the officers are the Police Commissioner, who is assisted by Deputy/Assistant Commissioners.
Officers advance up the ranks from PO to Captain by civil service exams (excluding Detective). I don’t know whether the exams for the higher ranks include just written tests, or have practical/interview components. Each officer ranking above Captain is legally a Captain under the civil service law, but is promoted to his or her higher rank and serves as such at the pleasure of the Police Commissioner.
Detective is a bit of an oddball rank. Officers can and do most frequently advance from PO to Sergeant without becoming a Detective, and Detectives frequently do not advance through the traditional ranks. I believe that one is appointed a detective to serve in certain positions in the Detective Bureau, the Organized Crime Control Bureau and certain other bureaus, though some Pos can serve in some detective positions before they are required to be given the gold shield of a detective. I’m not really sure how it works, however.
There are different grades of detective, and I believe that it officially has to do with their pay rates. I think that Detectives Second Grade are paid at the rate of a Sergeant, and the 100 Detectives First Grade are paid like Lieutenants. However, the higher grade detectives don’t have official supervisory responsibility, though they do have a great deal of respect. In addition, Sergeants and Lieutenants who supervise detectives can get a pay bump to that of a higher rank.
There is a supervisory chain of command in each bureau. Precincts can be commanded by Captains, Deputy Inspectors or Inspectors (I believe) and there are Sergeants and Lieutenants (and higher ranks) who are intermediate supervisors in precincts and in specialized bureaus. I understand that most Precinct detective squads are supervised by a Sergeant or a Lieutenant.
For what it is worth, much of my information is taken from reading the more accurate sort of NYPD police procedural novels, as well as non-fiction reading.