<?xml version="1.0"?>
<ownershipDocument>

    <schemaVersion>X0609</schemaVersion>

    <documentType>4</documentType>

    <periodOfReport>2026-05-01</periodOfReport>

    <notSubjectToSection16>0</notSubjectToSection16>

    <issuer>
        <issuerCik>0001170858</issuerCik>
        <issuerName>COMPANHIA DE SANEAMENTO BASICO DO ESTADO DE SAO PAULO-SABESP</issuerName>
        <issuerTradingSymbol>SBSP3</issuerTradingSymbol>
        <issuerForeignTradingSymbol>SBS</issuerForeignTradingSymbol>
    </issuer>

    <reportingOwner>
        <reportingOwnerId>
            <rptOwnerCik>0002119932</rptOwnerCik>
            <rptOwnerName>Szlak Daniel</rptOwnerName>
        </reportingOwnerId>
        <reportingOwnerAddress>
            <rptOwnerNonUSAddressFlag>true</rptOwnerNonUSAddressFlag>
            <rptOwnerStreet1>300 COSTA CARVALHO STREET</rptOwnerStreet1>
            <rptOwnerStreet2></rptOwnerStreet2>
            <rptOwnerCity>SAO PAULO</rptOwnerCity>
            <rptOwnerNonUSStateTerritory></rptOwnerNonUSStateTerritory>
            <rptOwnerCountry>D5</rptOwnerCountry>
            <rptOwnerZipCode>05429-900</rptOwnerZipCode>
            <rptOwnerStateDescription>BRAZIL</rptOwnerStateDescription>
        </reportingOwnerAddress>
        <reportingOwnerRelationship>
            <isDirector>0</isDirector>
            <isOfficer>1</isOfficer>
            <isTenPercentOwner>0</isTenPercentOwner>
            <isOther>0</isOther>
            <officerTitle>Chief Financial Officer</officerTitle>
            <otherText></otherText>
        </reportingOwnerRelationship>
    </reportingOwner>

    <aff10b5One>0</aff10b5One>

    <nonDerivativeTable>
        <nonDerivativeTransaction>
            <securityTitle>
                <value>Common Shares</value>
            </securityTitle>
            <transactionDate>
                <value>2026-05-01</value>
            </transactionDate>
            <deemedExecutionDate></deemedExecutionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>M</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionTimeliness></transactionTimeliness>
            <transactionAmounts>
                <transactionShares>
                    <value>10181</value>
                </transactionShares>
                <transactionPricePerShare>
                    <footnoteId id="F1"/>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>A</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>10181</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </nonDerivativeTransaction>
        <nonDerivativeTransaction>
            <securityTitle>
                <value>Common Shares</value>
            </securityTitle>
            <transactionDate>
                <value>2026-05-01</value>
            </transactionDate>
            <deemedExecutionDate></deemedExecutionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>F</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionTimeliness></transactionTimeliness>
            <transactionAmounts>
                <transactionShares>
                    <value>2800</value>
                </transactionShares>
                <transactionPricePerShare>
                    <value>6.69</value>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>D</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>7381</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </nonDerivativeTransaction>
    </nonDerivativeTable>

    <derivativeTable>
        <derivativeTransaction>
            <securityTitle>
                <value>Restricted Stock Units</value>
            </securityTitle>
            <conversionOrExercisePrice>
                <footnoteId id="F1"/>
            </conversionOrExercisePrice>
            <transactionDate>
                <value>2026-05-01</value>
            </transactionDate>
            <deemedExecutionDate></deemedExecutionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>M</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionTimeliness></transactionTimeliness>
            <transactionAmounts>
                <transactionShares>
                    <value>10181</value>
                </transactionShares>
                <transactionPricePerShare>
                    <value>0</value>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>D</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <exerciseDate>
                <footnoteId id="F1"/>
            </exerciseDate>
            <expirationDate>
                <footnoteId id="F1"/>
            </expirationDate>
            <underlyingSecurity>
                <underlyingSecurityTitle>
                    <value>Common Shares</value>
                </underlyingSecurityTitle>
                <underlyingSecurityShares>
                    <value>10181</value>
                </underlyingSecurityShares>
            </underlyingSecurity>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>30533</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </derivativeTransaction>
    </derivativeTable>

    <footnotes>
        <footnote id="F1">On April 29, 2025, the reporting person was granted an aggregate of 40,715 restricted stock units (&quot;RSUs&quot;), vesting pro rata on each of May 1, 2026, May 1, 2027, May 1, 2028 and May 1, 2029, subject to continued service as an officer of the issuer. Each RSU represents the contingent right to receive one Common Share of the Issuer upon vesting.</footnote>
    </footnotes>

    <remarks>All amounts reported in this Form 4 reflect certain recent events exempt from reporting under Section 16(a), namely (i) the receipt of rights to receive dividend equivalents (the accrual of which in this Form 4 upon vesting of the RSUs); (ii) the capital increase that occurred in March 2026; and (iii) the stock split approved by the Issuer's shareholders in April 2026.
Due to the issuer's status as a foreign private issuer pursuant to Rule 3a12-3(b) under the Securities Exchange Act of 1934 (the &quot;Act&quot;), the reporting person's transactions in the issuer's equity securities are exempt from Sections 16(b) and 16(c) of the Act.</remarks>

    <ownerSignature>
        <signatureName>/s/ Beatriz Caroline de Sousa Daher, as attorney-in-fact for Daniel Szlak</signatureName>
        <signatureDate>2026-05-15</signatureDate>
    </ownerSignature>
</ownershipDocument>