[WILSON, SONSINI, GOODRICH & ROSATI LETTERHEAD]

                                                                     EXHIBIT 5.1

                               February 18, 2000

Hewlett-Packard Company

3000 Hanover Street

Palo Alto, California 94304

    RE: HEWLETT-PACKARD COMPANY--REGISTRATION STATEMENT ON FORM S-3

Ladies and Gentlemen:

    At your request, we have examined the Registration Statement on Form S-3
(the "Registration Statement"), filed by Hewlett-Packard Company, a Delaware
corporation (the "Company"), with the Securities and Exchange Commission in
connection with the registration pursuant to the Securities Act of 1933, as
amended (the "Act"), with an aggregate offering price of up to $3,000,000,000 or
the equivalent thereof, of the Company's senior and subordinated debt securities
(the "Debt Securities"), shares of Common Stock, $0.01 par value per share (the
"Common Stock"), shares of the Preferred Stock, $0.01 par value per share (the
"Preferred Stock"), depositary shares (the "Depositary Shares") of the Company
representing a fractional interest in a share of Preferred Stock and/or warrants
to purchase Debt Securities, Preferred Stock or Common Stock (the "Warrants") of
the Company (the Debt Securities, Common Stock, Preferred Stock, Depositary
Shares and Warrants are collectively referred to herein as the "Securities").
The Securities are to be sold from time to time as set forth in the Registration
Statement, the Prospectus contained therein (the "Prospectus") and the
supplements to the Prospectus (the "Prospectus Supplements"). The Debt
Securities are to be issued pursuant to a Senior Debt Securities Indenture (the
"Senior Indenture") and a Subordinated Debt Securities Indenture (the
"Subordinated Indenture"), each of which will be filed as exhibits to the
Registration Statement (the "Indentures") and are to be entered into in each
case between the Company and State Street Bank and Trust Company of California,
N.A. (the "Trustee"). The Securities are to be sold pursuant to an underwriting
agreement (the "Underwriting Agreement"), in substantially the form to be filed
under a Current Report on Form 8-K. The Debt Securities are to be issued in the
forms set forth in the Indentures filed as exhibits to the Registration
Statement.

    We have examined instruments, documents and records which we deemed relevant
and necessary for the basis of our opinion hereinafter expressed. In such
examination, we have assumed (a) the authenticity of original documents and the
genuineness of all signatures, (b) the conformity to the originals of all
documents submitted to us as copies and (c) the truth, accuracy, and
completeness of the information, representations and warranties contained in the
records, documents, instruments and certificates we have reviewed.

    Based on such examination, we are of the opinion that:

    1.  with respect to Debt Securities to be issued under either the Senior
Indenture or Subordinated Indenture, when (A) the Trustee is qualified to act as
Trustee under the Senior Indenture or Subordinated Indenture, as applicable,
(B) the Trustee has duly executed and delivered the Subordinated Indenture or
Senior Indenture, as applicable, (C) the Senior Indenture or Subordinated
Indenture, as applicable, has been duly authorized and validly executed and
delivered by the Company to the Trustee (D) the Senior Indenture or Subordinated
Indenture, as applicable, has been duly qualified under the Trust Indenture Act
of 1939, as amended, (E) the Board of Directors of the Company or a duly
constituted and acting committee thereof (such Board of Directors or committee,
including the Executive Committee of the Board of Directors, being hereinafter
referred to as the "Board") has taken all necessary corporate action, and
appropriate corporate officers of the Company have taken all appropriate action
in accordance with such corporate action to approve the issuance and

terms of such Debt Securities, the terms of the offering thereof and related
matters, and (F) such Debt Securities have been duly executed, authenticated,
issued and delivered in accordance with the provisions of the Senior Indenture
or Subordinated Indenture, as applicable, and the applicable definitive
purchase, underwriting or similar agreement approved by the Board upon payment
of the consideration therefor provided for therein, such Debt Securities will be
validly issued and will constitute valid and binding obligations of the Company,
enforceable against the Company in accordance with their terms;

    2.  with respect to shares of Preferred Stock, when both (A) the Board has
taken all necessary corporate action to approve the issuance and terms of the
shares of Preferred Stock, the terms of the offering thereof, and related
matters, including the adoption of a Certificate of Amendment relating to such
Preferred Stock (a "Certificate") and the filing of the Certificate with the
Secretary of State of the State of Delaware, and (B) certificates representing
the shares of Preferred Stock have been duly executed, countersigned, registered
and delivered either (i) in accordance with the applicable definitive purchase,
underwriting or similar agreement approved by the Board upon payment of the
consideration therefor (not less than the par value of the Preferred Stock)
provided for therein or (ii) upon conversion or exercise of such Security or the
instrument governing such Security providing for such conversion or exercise as
approved by the Board, for the consideration approved by the Board (not less
than the par value of the Preferred Stock), then the shares of Preferred Stock
will be validly issued, fully paid and nonassessable;

    3.  with respect to with respect to Depositary Shares, when (A) the Board
has taken all necessary corporate action to approve the issuance and terms of
the Depositary Shares, the terms of the offering thereof, and related matters,
including the adoption of a Certificate relating to the Preferred Stock
underlying such Depositary Shares and the filing of the Certificate with the
Secretary of State of the State of Delaware, (B) the Deposit Agreement (the
"Deposit Agreement") or Agreements relating to the Depositary Shares and the
related Depositary Receipts have been duly authorized and validly executed and
delivered by the Company and the Depositary appointed by the Company, (C) the
shares of Preferred Stock underlying such Depositary Shares have been deposited
with a bank or trust company (which meets the requirements for the Depositary
set forth in the Registration Statement) under the applicable Deposit Agreement,
and (D) the Depositary Receipts representing the Depositary Shares have been
duly executed, countersigned, registered and delivered in accordance with the
appropriate Deposit Agreement and the applicable definitive purchase,
underwriting or similar agreement approved by the Board upon payment of the
consideration therefor provided for therein, the Depositary Shares will be
validly issued;

    4.  with respect to shares of Common Stock, when both (A) the Board has
taken all necessary corporate action to approve the issuance of and the terms of
the offering of the shares of Common Stock and related matters and
(B) certificates representing the shares of Common Stock have been duly
executed, countersigned, registered and delivered either (i) in accordance with
the applicable definitive purchase, underwriting or similar agreement approved
by the Board upon payment of the consideration therefor (not less than the par
value of the Common Stock) provided for therein or (ii) upon conversion or
exercise of any other Security, in accordance with the terms of such Security or
the instrument governing such Security providing for such conversion or exercise
as approved by the Board, for the consideration approved by the Board (not less
than the par value of the Common Stock), then the shares of Common Stock will be
validly issued, fully paid and nonassessable; and

    5.  with respect to the Warrants, when (A) the Board has taken all necessary
corporate action to approve the creation of and the issuance and terms of the
Warrants, the terms of the offering thereof, and related matters, (B) the
Warrant Agreement or Agreements relating to the Warrants have been duly
authorized and validly executed and delivered by the Company and the Warrant
Agent appointed by the Company, and (C) the Warrants or certificates
representing the Warrants have been duly executed, countersigned, registered and
delivered in accordance with the appropriate Warrant Agreement or Agreements and
the applicable definitive purchase, underwriting or similar agreement approved
by the Board upon payment of the consideration therefor provided for therein,
the Warrants will be validly issued.

    Our opinion that any document is legal, valid and binding is qualified as
to:

    (a) limitations imposed by bankruptcy, insolvency, reorganization,
arrangement, fraudulent conveyance, moratorium or other laws relating to or
affecting the rights of creditors generally; and

    (b) general principles of equity, including without limitation concepts of
materiality, reasonableness, good faith and fair dealing, and the possible
unavailability of specific performance or injunctive relief, regardless of
whether such enforceability is considered in a proceeding in equity or at law.

    We hereby consent to the filing of this opinion as an exhibit to the
above-referenced Registration Statement and to the use of our name wherever it
appears in the Registration Statement, the Prospectus, the Prospectus
Supplement, and in any amendment or supplement thereto. In giving such consent,
we do not believe that we are "experts" within the meaning of such term as used
in the Act or the rules and regulations of the Securities and Exchange
Commission issued thereunder with respect to any part of the Registration
Statement, including this opinion as an exhibit or otherwise.

                                          /s/ WILSON SONSINI GOODRICH & ROSATI

                                          WILSON SONSINI GOODRICH & ROSATI
                                          Professional Corporation