<?xml version="1.0" encoding="utf-8"?>
<xbrl
  xmlns="http://www.xbrl.org/2003/instance"
  xmlns:dei="http://xbrl.sec.gov/dei/2025"
  xmlns:link="http://www.xbrl.org/2003/linkbase"
  xmlns:xlink="http://www.w3.org/1999/xlink">
    <link:schemaRef xlink:href="unf-20260310.xsd" xlink:type="simple"/>
    <context id="duration_2026-03-10_to_2026-03-10">
        <entity>
            <identifier scheme="http://www.sec.gov/CIK">0000717954</identifier>
        </entity>
        <period>
            <startDate>2026-03-10</startDate>
            <endDate>2026-03-10</endDate>
        </period>
    </context>
    <dei:EntityRegistrantName
      contextRef="duration_2026-03-10_to_2026-03-10"
      id="Hidden_dei_EntityRegistrantName">UNIFIRST CORP</dei:EntityRegistrantName>
    <dei:CurrentFiscalYearEndDate
      contextRef="duration_2026-03-10_to_2026-03-10"
      id="Hidden_dei_CurrentFiscalYearEndDate_duration_2026-03-10_to_2026-03-10">--08-29</dei:CurrentFiscalYearEndDate>
    <dei:AmendmentFlag
      contextRef="duration_2026-03-10_to_2026-03-10"
      id="Hidden_dei_AmendmentFlag_duration_2026-03-10_to_2026-03-10">false</dei:AmendmentFlag>
    <dei:EntityCentralIndexKey
      contextRef="duration_2026-03-10_to_2026-03-10"
      id="Hidden_dei_EntityCentralIndexKey_duration_2026-03-10_to_2026-03-10">0000717954</dei:EntityCentralIndexKey>
    <dei:DocumentType contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_1">8-K</dei:DocumentType>
    <dei:DocumentPeriodEndDate contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_0">2026-03-10</dei:DocumentPeriodEndDate>
    <dei:EntityIncorporationStateCountryCode contextRef="duration_2026-03-10_to_2026-03-10" id="ixv-568">MA</dei:EntityIncorporationStateCountryCode>
    <dei:EntityFileNumber contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_19">001-08504</dei:EntityFileNumber>
    <dei:EntityTaxIdentificationNumber contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_18">04-2103460</dei:EntityTaxIdentificationNumber>
    <dei:EntityAddressAddressLine1 contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_22">68 Jonspin Road</dei:EntityAddressAddressLine1>
    <dei:EntityAddressCityOrTown contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_17">Wilmington</dei:EntityAddressCityOrTown>
    <dei:EntityAddressStateOrProvince contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_25">MA</dei:EntityAddressStateOrProvince>
    <dei:EntityAddressPostalZipCode contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_16">01887</dei:EntityAddressPostalZipCode>
    <dei:CityAreaCode contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_21">978</dei:CityAreaCode>
    <dei:LocalPhoneNumber contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_20">658-8888</dei:LocalPhoneNumber>
    <dei:WrittenCommunications contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_4">true</dei:WrittenCommunications>
    <dei:SolicitingMaterial contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_6">false</dei:SolicitingMaterial>
    <dei:PreCommencementTenderOffer contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_8">false</dei:PreCommencementTenderOffer>
    <dei:PreCommencementIssuerTenderOffer contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_10">false</dei:PreCommencementIssuerTenderOffer>
    <dei:Security12bTitle contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_13">Common Stock, $0.10 par value per share</dei:Security12bTitle>
    <dei:TradingSymbol contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_14">UNF</dei:TradingSymbol>
    <dei:SecurityExchangeName contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_15">NYSE</dei:SecurityExchangeName>
    <dei:EntityEmergingGrowthCompany contextRef="duration_2026-03-10_to_2026-03-10" id="Fact_12">false</dei:EntityEmergingGrowthCompany>
</xbrl>
