Because by May of 2020, they must submit their latest annual energy-use data, which comes from the utility companies that service them, to an online tool created by the Environmental Protection Agency. The tool will calculate greenhouse emissions and take into account factors like building type and number of occupants. The buildings will then submit their scores to the city. The letter grades will be based on the scores generated by the E.P.A. tool: D’s will go to the energy guzzlers.

Building owners and managers will be required to post signs with the letter grades “in a conspicuous location near each public entrance,” according to the law. Failure to do so will be a violation, subject to a fine, said a buildings department spokesman in an email.

The posting of grades is a sort of “name and shame” strategy, but in phone interviews, city officials chose to speak about “transparency.”

“People want to know what they are walking into, what they are living in and what their contribution to meeting their values are,” said Melanie E. La Rocca, commissioner of the buildings department.

“It’s a nutrition label for our buildings,” said Mark Chambers, the director of the Mayor’s Office of Sustainability.

Some who advise building owners, however, say there is a difference between the restaurant grades, which convey health department assessments based on surprise inspections, and the building grades.

“If I show up at a restaurant with a C, I’m not stepping in the door,” said David Klatt, a senior vice president of Logical Buildings, which advises companies on reducing energy use. It is not clear, he said, how city residents will react to a middling or even low grade of their home or place of work.