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

    <schemaVersion>X0508</schemaVersion>

    <documentType>4</documentType>

    <periodOfReport>2025-05-14</periodOfReport>

    <issuer>
        <issuerCik>0001201792</issuerCik>
        <issuerName>AMERICAN PUBLIC EDUCATION INC</issuerName>
        <issuerTradingSymbol>APEI</issuerTradingSymbol>
    </issuer>

    <reportingOwner>
        <reportingOwnerId>
            <rptOwnerCik>0001220428</rptOwnerCik>
            <rptOwnerName>SUNDERLAND RICHARD W JR</rptOwnerName>
        </reportingOwnerId>
        <reportingOwnerAddress>
            <rptOwnerStreet1>111 WEST CONGRESS STREET</rptOwnerStreet1>
            <rptOwnerStreet2></rptOwnerStreet2>
            <rptOwnerCity>CHARLES TOWN</rptOwnerCity>
            <rptOwnerState>WV</rptOwnerState>
            <rptOwnerZipCode>25414</rptOwnerZipCode>
            <rptOwnerStateDescription></rptOwnerStateDescription>
        </reportingOwnerAddress>
        <reportingOwnerRelationship>
            <isDirector>0</isDirector>
            <isOfficer>1</isOfficer>
            <isTenPercentOwner>0</isTenPercentOwner>
            <isOther>0</isOther>
            <officerTitle>EVP, Chief Financial Officer</officerTitle>
        </reportingOwnerRelationship>
    </reportingOwner>

    <aff10b5One>0</aff10b5One>

    <nonDerivativeTable>
        <nonDerivativeTransaction>
            <securityTitle>
                <value>Common Stock, par value $.01</value>
            </securityTitle>
            <transactionDate>
                <value>2025-05-14</value>
            </transactionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>S</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionAmounts>
                <transactionShares>
                    <value>2133</value>
                </transactionShares>
                <transactionPricePerShare>
                    <value>26.9979</value>
                    <footnoteId id="F1"/>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>D</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>187403</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </nonDerivativeTransaction>
        <nonDerivativeTransaction>
            <securityTitle>
                <value>Common Stock, par value $.01</value>
            </securityTitle>
            <transactionDate>
                <value>2025-05-14</value>
            </transactionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>S</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionAmounts>
                <transactionShares>
                    <value>4155</value>
                </transactionShares>
                <transactionPricePerShare>
                    <value>27.4697</value>
                    <footnoteId id="F2"/>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>D</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>183248</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </nonDerivativeTransaction>
        <nonDerivativeTransaction>
            <securityTitle>
                <value>Common Stock, par value $.01</value>
            </securityTitle>
            <transactionDate>
                <value>2025-05-15</value>
            </transactionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>S</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionAmounts>
                <transactionShares>
                    <value>5924</value>
                </transactionShares>
                <transactionPricePerShare>
                    <value>27.3985</value>
                    <footnoteId id="F3"/>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>D</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>177324</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </nonDerivativeTransaction>
        <nonDerivativeTransaction>
            <securityTitle>
                <value>Common Stock, par value $.01</value>
            </securityTitle>
            <transactionDate>
                <value>2025-05-15</value>
            </transactionDate>
            <transactionCoding>
                <transactionFormType>4</transactionFormType>
                <transactionCode>S</transactionCode>
                <equitySwapInvolved>0</equitySwapInvolved>
            </transactionCoding>
            <transactionAmounts>
                <transactionShares>
                    <value>20</value>
                </transactionShares>
                <transactionPricePerShare>
                    <value>27.9285</value>
                    <footnoteId id="F4"/>
                </transactionPricePerShare>
                <transactionAcquiredDisposedCode>
                    <value>D</value>
                </transactionAcquiredDisposedCode>
            </transactionAmounts>
            <postTransactionAmounts>
                <sharesOwnedFollowingTransaction>
                    <value>177304</value>
                </sharesOwnedFollowingTransaction>
            </postTransactionAmounts>
            <ownershipNature>
                <directOrIndirectOwnership>
                    <value>D</value>
                </directOrIndirectOwnership>
            </ownershipNature>
        </nonDerivativeTransaction>
    </nonDerivativeTable>

    <footnotes>
        <footnote id="F1">The price of $26.9979 per share represents a weighted average of sale prices ranging from $26.25 to $27.23 per share. The reporting person undertakes to provide upon request by the Commission staff, the issuer, or a security holder of the issuer full information regarding the number of shares sold at each separate price.</footnote>
        <footnote id="F2">The price of $27.4697 per share represents a weighted average of sale prices ranging from $27.25 to $27.88 per share. The reporting person undertakes to provide upon request by the Commission staff, the issuer, or a security holder of the issuer full information regarding the number of shares sold at each separate price.</footnote>
        <footnote id="F3">The price of $27.3985 per share represents a weighted average of sale prices ranging from $26.88 to $27.875 per share. The reporting person undertakes to provide upon request by the Commission staff, the issuer, or a security holder of the issuer full information regarding the number of shares sold at each separate price.</footnote>
        <footnote id="F4">The price of $27.9285 per share represents a weighted average of sale prices ranging from $27.91 to $27.965 per share. The reporting person undertakes to provide upon request by the Commission staff, the issuer, or a security holder of the issuer full information regarding the number of shares sold at each separate price.</footnote>
    </footnotes>

    <ownerSignature>
        <signatureName>/s/ Richard W. Sunderland, Jr.</signatureName>
        <signatureDate>2025-05-16</signatureDate>
    </ownerSignature>
</ownershipDocument>
