Since 1993, we have issued seven decisions related to this litigation. After our decision in Claremont School District v. Governor, 142 N.H. 462, 703 A.2d 1353 (1997) (Claremont II), the plaintiffs, five school districts, five students, and eight taxpayers and parents, filed a motion for taxation of costs pursuant to Supreme Court Rule 23, and filed a separate motion seeking to have the State pay their attorney’s fees and costs “for prevailing in the liability phase of the Claremont litigation.” In Claremont School District v. Governor (Motion for Extension of Deadlines), 143 N.H. 154, 160, 725 A.2d 648, 651 (1998), the State having failed to object, we granted the plaintiffs’ motion for taxation of costs and deferred consideration of their motion for attorney’s fees and costs.
The State moved to reconsider the award of costs. With respect to both the motion for reconsideration of the award of costs and the motion for attorney’s fees and costs, the State raises the defense of sovereign immunity. For reasons that follow, we now hold that sovereign immunity bars the award of costs but that it does not preclude the award of attorney’s fees to the plaintiffs.
In New Hampshire, the sovereign immunity of the State is based on two separate grounds. First, the State is immune from liability for torts committed by its officers and employees. Sousa v. State, 115 N.H. 340, 342, 341 A.2d 282, 284 (1975). Second, the State is immune from suit in its courts without its consent. Id.; see Tilton v. Dougherty, 126 N.H. 294, 297, 493 A.2d 442, 444 (1985). Both the State’s immunity from suit and its immunity from liability for torts are “traced back to the immunity of the British Crown carried over to the States by the courts.” Sousa, 115 N.H. at 342, 341 A.2d at 284. Sovereign immunity “rested on a common law basis in this State until the enactment in 1978 of RSA 99-D:l, . . . which adopted [the] doetrine[] ‘as the law of the state,’ except where a statute might provide an exception.” Tilton, 126 N.H. at 298, 493 A.2d at 444.
*592The contents and scope of the doctrine[] as adopted by the legislature are not described in the statute itself, and we are aware of no legislative history indicating the legislature’s assumptions. It is reasonable to infer, therefore, that when the legislature placed the doctrine[] of sovereign . . . immunity on a statutory basis it intended to adopt the common law of the State as it existed at the enactment of the statute in 1978.
Id.
As an initial matter, the plaintiffs argue that the State waived its objection to their motion for taxation of costs because it did not object within the ten days required by Supreme Court Rule 21. In LaRoche, Administrator v. Doe, 134 N.H. 562, 594 A.2d 1297 (1991), however, we rejected a similar argument. The plaintiff in LaRoehe argued that because the attorney general did not file a special appearance or assert sovereign immunity in a brief statement, special plea, or pretrial statement, the State had waived its sovereign immunity. We concluded that “[s]overeign immunity is a jurisdictional question not to be waived by conduct or undermined by estoppel,” LaRoche, 134 N.H. at 566, 594 A.2d at 1300 (quotation omitted), and that “[i]t is not a defense which must be affirmatively pled.” Id.
Neither improvident procedural choices, nor the tardiness of the State’s attorney in raising sovereign immunity, can be a proper basis for finding that immunity waived. Because the State’s sovereign immunity may be waived only by the legislature, a fortiori the State’s actions in failing to swiftly seek dismissal of this case . . . had no effect as a waiver of the State’s basic immunity from suit.
Id. at 567-68, 594 A.2d at 1301. The State’s challenge on the basis of sovereign immunity to the costs we awarded pursuant to Supreme Court Rule 23 is, therefore, a challenge to the court’s subject matter jurisdiction, which may be raised at any time. See K & J Assoc. v. City of Lebanon, 142 N.H. 331, 333, 703 A.2d 253, 254 (1997). Accordingly, we conclude that the State did not waive its objection to the motion for taxation of costs.
The State generally is immune from suit in its courts without its consent. The plaintiffs were entitled to maintain their suit in this case even without legislative consent, however, because their theory was that the official actions taken by the defendants were unconstitutional.
*593When a law is challenged as unconstitutional, the claim is that the law is void and hence that no law has been enacted. It follows that if the legislature has not acted under authority, no action has been taken by the State, and hence when suit is brought to restrain those representing the State from carrying the void legislation into operation and enforcing it, it is not a proceeding to which the State is a party. What is forbidden by the Constitution is outside the field of state activity; restraint of forbidden action is not imposed by the courts upon the State but upon those asserting the right to take the action as though it were the State’s and as though binding upon it.
Conway v. Water Resources Board, 89 N.H. 346, 348, 199 A. 83, 86 (1938) (citations omitted); see O’Neil v. Thomson, 114 N.H. 155, 159, 316 A.2d 168, 170-71 (1974).
The declaratory judgment statute, RSA 491:22 (1997), “has long been construed to permit challenges to the constitutionality of actions by our government or its branches.” Grinnell v. State, 121 N.H. 823, 825, 435 A.2d 523, 525 (1981). Because the plaintiffs sought injunctive relief and a declaratory judgment that the system by which the State funded public education was unconstitutional and thus void, the court had jurisdiction to grant equitable relief. Therefore, sovereign immunity would not bar the underlying action, regardless of whether the State consented to suit. We turn to determine, however, whether sovereign immunity would apply to bar an award of either costs or attorney’s fees arising from litigation that is not otherwise barred by the doctrine.
As a general rule, costs are “allowable only when authorized by statute or court rule.” 20 C.J.S. Costs § 4, at 11-12 (1990); see 5 R. Wiebush, New Hampshire Practice Civil Practice and PROCEDURE § 51.02, at 374 (2d ed. 1998).
Costs may not be enforced against the sovereign in the absence of a waiver, and the State will not be deemed to have waived unless it does so expressly or by implication of such reasonable clarity that the courts need not strain the words of the statute to reach a conclusion.
Ranger v. N.H. Youth Dev. Center, 118 N.H. 163, 165, 384 A.2d 493, 495 (1978) (citation and quotations omitted).
Thus, notwithstanding the inapplicability of sovereign immunity to the underlying litigation, sovereign immunity bars an award *594of costs absent a legislative waiver of immunity. Because the legislature has not waived the State’s immunity from costs pursuant to Rule 23, the State cannot be assessed costs in this matter. We therefore grant the State’s motion for reconsideration of the award of costs in the amount of $18,646.82, and vacate our order of November 25, 1998, awarding such costs. Additionally, we deny the plaintiffs’ subsequent motion for costs.
We have never decided, however, whether sovereign immunity bars an award of attorney’s fees. We note that in St. Germain v. Adams, 117 N.H. 659, 662-63, 377 A.2d 620, 623 (1977), and Harkeem v. Adams, 117 N.H. 687, 692-93, 377 A.2d 617, 620 (1977), we awarded fees against the State without addressing sovereign immunity. Additionally, in Foote v. State Personnel Comm’n, 118 N.H. 640, 644-45, 392 A.2d 156, 159-60 (1978), although we addressed the merits of the plaintiff’s argument that she was entitled to attorney’s fees pursuant to Harkeem, we rejected the plaintiff’s arguments with respect to costs and interest on the basis of sovereign immunity.
The plaintiffs in this case base their request for attorney’s fees on two theories — the “bad faith litigation” theory, see Harkeem, 117 N.H. at 690-91, 377 A.2d at 619, and the “substantial benefit” theory, see Irwin Marine, Inc. v. Blizzard, Inc., 126 N.H. 271, 276, 490 A.2d 786, 791 (1985). These theories are grounded upon the rationale that “[w]hen overriding considerations so indicate, the award of fees lies within the power of the court, and is an appropriate tool in the court’s arsenal to do justice and vindicate rights.” Silva v. Botsch, 121 N.H. 1041, 1043-44, 437 A.2d 313, 315 (1981) (quotation omitted). In contrast to the authority for awarding costs, which rests upon a statute or court rule that provides for costs as a matter of right, the authority for awarding attorney’s fees in this case lies within the court’s equity jurisdiction, and “equity is deemed to have power to grant relief.” Conway, 89 N.H. at 348, 199 A. at 86.
The court has “broad and flexible equitable powers which allow it to shape and adjust the precise relief to the requirements of the particular situation.” Dunlop v. Daigle, 122 N.H. 295, 300, 444 A.2d 519, 521 (1982) (quotation omitted). “[A] court of equity . . . will order to be done that which in fairness and good conscience ought to be or should have been done.” Langevin v. Hillsborough County, 114 N.H. 317, 320, 320 A.2d 635, 636 (1974). “It is the practice of courts of equity, having jurisdiction, to administer all relief which the nature of the case and facts demand.” Baldwin v. Wallace, 84 N.H. 71, 72, 146 A. 90, 91 (1929) (quotation omitted); see *595N.H. Donuts, Inc. v. Skipitaris, 129 N.H. 774, 783, 533 A.2d 351, 355 (1987) (it is the historic purpose of equity to secure complete justice, and courts are able to adjust the remedies so as to grant the necessary relief). We conclude that an award of attorney’s fees is not barred by sovereign immunity in this case because the underlying case is not barred by the doctrine, the relief the plaintiffs seek in the form of fees is within our inherent equitable power, and we have equitable jurisdiction over this case.
We now turn to the merits of the plaintiffs’ motion for attorney’s fees. At the outset, we reject the plaintiffs’ argument that the State’s conduct in this litigation has been in bad faith, forcing the plaintiffs “to seek judicial assistance to secure a clearly defined and established right.” Harkeem, 117 N.H. at 691, 377 A.2d at 619. The obligations of the State sought to be defined by the plaintiffs in this litigation were neither clearly defined nor established prior to our decisions in Claremont School District v. Governor, 138 N.H. 183, 635 A.2d 1375 (1993) (Claremont I), and Claremont II. Moreover, we disagree that the post-Claremont II actions of the State relied upon by the plaintiffs in their motion rise to the level of bad faith. We agree, however, with the plaintiffs that they are entitled to an award of fees under the substantial benefit theory.
An award of attorney’s fees to the prevailing party where the action conferred a substantial benefit on not only the plaintiffs who initiated the action, but on the public as well, has been recognized as an exception to the American rule that each party must bear its own attorney’s fees. See Silva, 121 N.H. at 1043, 437 A.2d at 314; Irwin Marine, 126 N.H. at 276, 490 A.2d at 791; see also Mills v. Electric Auto-Lite, 396 U.S. 375, 393-94 (1970) (reimbursement permitted in cases where the litigation has conferred a substantial benefit on the members of an ascertainable class, and where the court’s jurisdiction over the subject matter of the suit makes possible an award that will operate to spread the costs proportionately among them). “To award attorneys’ fees in such a suit to a plaintiff who has succeeded in establishing a cause of action is not to saddle the unsuccessful party with the expenses but to impose them on the class that has benefitted from them and that would have had to pay them had it brought the suit.” Mills, 396 U.S. at 396-97. “|T]he good or bad faith of the defendants is not a consideration in the award of attorney’s fees under this exception.” Silva, 121 N.H. at 1044, 437 A.2d at 315. The purpose of the fee award in this case is not to penalize the State, but rather to compensate the plaintiff towns for their efforts on behalf of the public.
*596The issues involved in this litigation combine two significant rights specifically protected by the State Constitution and of primary concern to New Hampshire citizens; namely, education and taxation. The plaintiffs initiated an action for declaratory and injunctive relief and successfully established that Part II, Article 83 of the State Constitution imposes a duty on the State to provide a constitutionally adequate public education and to guarantee its adequate funding, see Claremont I, 138 N.H. at 184, 635 A.2d at 1376, and that the property tax then levied to fund education was disproportionate and unreasonable in violation of Part II, Article 5, see Claremont II, 142 N.H. at 471, 703 A.2d at 1357.
The decisions in Claremont I and Claremont II recognize the seminal role education plays in our society. The New Hampshire Constitution “expressly recognizes that a free government is dependent for its survival on citizens who are able to participate intelligently in the political, economic, and social functions of our system.” Claremont I, 138 N.H. at 192, 635 A.2d at 1381; see Claremont II, 142 N.H. at 469, 703 A.2d at 1356 (“No other governmental service plays such a seminal role in developing and maintaining a citizenry capable of furthering the economic, political, and social viability of the State.”). An adequate education for all our public school students is critical to the preservation of our democracy and to our citizens’ success in a complex, evolving society. See Claremont II, 142 N.H. at 474, 703 A.2d at 1359. Thus, we concluded that “in this State a constitutionally adequate public education is a fundamental right . . . held by the public to enforce the State’s duty.” Id. at 473, 703 A.2d at 1359.
In addition, proportional and reasonable taxation is one of the core constitutional foundations of this State. In Claremont II, we held that to allow the then-existing system of financing public education to continue “would be to effectively conclude that it is reasonable, in discharging a State obligation, to tax property owners in one town or city as much as four times the amount taxed to others similarly situated in other towns and cities.”. Claremont II, 142 N.H. at 465, 703 A.2d at 1354. Such a system effected “precisely the kind of taxation and fiscal mischief from which the framers of our State Constitution took strong steps to protect our citizens.” Id. At the time of the decision in Claremont II, for example, in order to provide some level of public education, taxpayers in Pittsfield incurred a school tax that was over 400 percent higher than those in Moultonborough, and taxpayers in Allenstown incurred a tax rate almost 400 percent higher than those in Rye. See id. at 470, 703 A.2d at 1356-57. It was the towns of Pittsfield and Allenstown, among *597others, already strained under the weight of the burden of the tax system and the least capable of sustaining their local governments and schools, that came forward and offered their own limited fiscal resources to benefit the rest of the State.
It is important to note that in 1982, the issue of inequality of education and school financing in New Hampshire was raised in the case of Jesseman v. State, No. 83-371 (N.H. February 13, 1984). The “property poor” school district plaintiffs in that action moved for voluntary dismissal because of amendments passed by the legislature in 1985 to the New Hampshire Foundation Aid Statute, RSA ch. 198. The amendments resulted in the “Augenblick Formula,” which the plaintiffs in Jesseman acknowledged would “result in a more equitable distribution of state aid to education in this state,” thereby relieving the need for the lawsuit. The funds promised to be distributed under the Augenblick Formula were, however, never appropriated to an extent so as to provide the promised relief. Thus, nearly ten years later, “property poor” school districts were again compelled to initiate litigation to remedy the ongoing constitutional violations.
In addition to Claremont I and Claremont II, we have issued five rulings related to this litigation, which for reference we summarize. In Claremont School District v. Governor (Motion to Vacate), 142 N.H. 737, 712 A.2d 612 (1998), in which retired Justice Batchelder’s participation in Claremont II was challenged, we ruled that RSA 490:3 (1997) authorizes justices over the age of seventy to sit temporarily and that that statute is constitutional. In Opinion of the Justices (School Financing), 142 N.H. 892, 712 A.2d 1080 (1998), we concluded that proposed legislation purporting to establish a uniform State education tax rate would be unconstitutional because of a special abatement provision which would have reduced the effective tax rate below the uniform State education tax rate in any town that raised more revenue than it needed to provide the legislatively defined adequate education for its children. In Claremont School District v. Governor (Motion for Extension of Deadlines), 143 N.H. 154, 725 A.2d 648 (1998), we denied the State’s motion to extend the validity of the current education system through the 2000 property tax year, finding no extraordinary circumstances to justify further delay in achieving a constitutional educational funding system. In Opinion of the Justices (Tax Plan Referendum), 143 N.H. 429, 725 A.2d 1082 (1999), we concluded that an act authorizing the legislature to seek the consent of the people, through a binding referendum, for a newly established tax to fund public education was an unconstitutional delegation of power from *598the legislature. Finally, in Claremont School District v. Governor, 144 N.H. 210, 744 A.2d 1107 (1999), we held that the phase-in component of the statewide education property tax was unconstitutional because it resulted in varying property tax rates that were unreasonable and disproportionate. We express no opinion as to whether attorney’s fees are recoverable for litigation related to these proceedings.
The public interest in preserving constitutional rights against governmental infringement is paramount. Only private citizens can be expected to “guard the guardians.” Nussbaum, Attorney’s Fees in Public Interest Litigation, 48 N.Y.U. L. REV. 301, 330 (1973). Because the benefits of this litigation flow to all members of the public, the plaintiffs should not have to bear the entire cost of this litigation.
The plaintiffs have contributed to the vindication of important constitutional rights. In doing so, they have conferred a significant benefit upon the general public, and it is thus the general public that would have had to pay the fees incurred if the general public had brought the suit. See Mills, 396 U.S. at 396-97. Under these facts, we find it an appropriate, if not compelling, case in which to exercise our inherent equitable powers and award reasonable attorney’s fees to the plaintiff school districts of Claremont, Franklin, Lisbon, Pittsfield, and Allenstown.
The parties are encouraged to resolve the reasonableness of the fees in this matter and are given until March 1, 2000, to do so. In the event that the plaintiffs and the State are unable to reach agreement by that date, the case shall be referred to a special master for the purpose of carrying into effect the holding in this matter. On referral, the master should make specific findings including the proceeding or proceedings for which the plaintiffs are entitled to fees, when the substantial benefit commenced, when it ended, and the reasonableness of the fees incurred. In determining reasonableness, the master should refer, as a minimum, to the rate charged by municipal counsel for services rendered in complex litigation. Additionally, the master should determine whether the plaintiffs are entitled to fees with respect to all the issues for which they seek reimbursement. Compare Funtown USA, Inc. v. Town of Conway, 129 N.H. 352, 356, 529 A.2d 882, 885 (1987) (award of attorney’s fees reduced by amount expended on unsuccessful claim that was analytically severable from remainder of the suit) with Daniels v. McKinney, 193 Cal. Rptr. 842, 848-49 (Ct. App. 1983) (rejecting argument that award of fees should be reduced by amount attrib*599utable to related claim on which prevailing parties were unsuccessful).
So ordered.
THAYER, J., did not participate; BATCHELDER, J., retired, sat by special assignment under RSA 490:3; all concurred.