Exhibit 5
GRADY & ASSOCIATES
ATTORNEYS & COUNSELORS AT LAW
20220 CENTER RIDGE ROAD, SUITE 300
ROCKY RIVER, OHIO 44116-3500
(440) 356-7255
November 26, 2024
Middlefield Banc Corp.
15985 East High Street
Middlefield, Ohio 44062
| Re: |   Dividend Reinvestment Plan  | 
Ladies and Gentlemen:
We have acted as counsel for Middlefield Banc Corp. (the “Company”) in connection with the filing of a Post-Effective Amendment No. 3 to the registration statement on Form S-3 (Registration No. 333-183497) pertaining to the Company’s Dividend Reinvestment Plan (the “Plan”) for the registration of 502,490 shares of common stock, no par value per share, to be filed with the Securities and Exchange Commission for issuance under the Plan. We have examined such documents, records, and matters of law as we have deemed necessary for the purposes of this opinion.
On the basis of the foregoing, we are of the opinion that Middlefield Banc Corp.’s shares of common stock that may be issued or transferred and sold according to the Dividend Reinvestment Plan will, when issued or transferred in accordance with the Dividend Reinvestment Plan, be duly authorized, validly issued, fully paid, and nonassessable.
We hereby consent to the filing of this opinion as Exhibit 5 to the Company’s Post-Effective Amendment No. 3 to the Registration Statement on Form S-3 and to the reference to our firm appearing in the prospectus filed as part of the Post-Effective Amendment No. 3, filed by the Company with the Securities and Exchange Commission relating to the Plan, as well as to any amendments or supplements thereto.
|   Sincerely yours,  | 
|   /s/ Grady & Associates  |