WASHINGTON — Georgia may not copyright its entire official code, which includes both the state’s laws and annotations interpreting them, the Supreme Court ruled on Monday. The 5-to-4 decision featured unusual alliances and would most likely be widely felt, as about 20 other states have claimed that parts of similar annotated codes are copyrighted.

“If everything short of statutes and opinions were copyrightable,” Chief Justice John G. Roberts Jr. wrote for the majority, “then states would be free to offer a whole range of premium legal works for those who can afford the extra benefit. A state could monetize its entire suite of legislative history. With today’s digital tools, states might even launch a subscription or pay-per-law service.”

Justices Sonia Sotomayor, Elena Kagan, Neil M. Gorsuch and Brett M. Kavanaugh joined the majority opinion.

The case, Georgia v. Public.Resource.Org, No. 18-1150, concerned the 54 volumes of the Official Code of Georgia Annotated, which contains state statutes and related materials. The state, through LexisNexis, a legal publisher, makes the statutes themselves available online, and it has said it does not object to others doing the same thing. But people who want to see the annotations, prepared by lawyers working for LexisNexis as part of a financial arrangement with the state, must pay.