• Outlook User
  • Exchange Admin
  • Office 365
  • Outlook Developer
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
    • Common Problems
    • Outlook BCM
    • Utilities & Addins

How to Compact the Data File When you Close Outlook

Slipstick Systems

› Outlook › Configure and Maintain › How to Compact the Data File When you Close Outlook

Last reviewed on February 15, 2021     13 Comments

It’s possible to configure Outlook to automatically compact the pst every time you close Outlook. I don’t recommend doing it (or emptying the deleted folder on exit) as it can lengthen the time it takes Outlook to shutdown and if Outlook is forced to close during the compaction process the data file could become corrupt.

However, this can be useful to users who deal with sensitive data and need to ensure messages can’t be recovered as compacting removes all traces of deleted messages, making it impossible to recover the mail.

Understanding Deletion and Compaction

After you delete messages and other Outlook items then empty the Deleted Item folder, the deleted items are removed from the index so Outlook doesn't display them but they are left in the data file. The space used by these deleted messages is often referred to as “white space”. Until Outlook recovers this space by compacting the data file, it may be possible to recover deleted messages using recovery software.

Outlook will automatically compact the data file when the “white space” reaches 20% of the data file’s size and the computer is idle. Because it runs as a background service, it can take days for Outlook to finish compacting the pst file. (If you leave Outlook open when the computer is running it will have more idle time to compact the data file.)

If you deleted a lot of messages and don’t want to wait for Outlook to get around to it, you can recover the free space by running Compact Now. To do this, right-click on the top-level of the data file and choose Properties, then click the Advanced button and Compact Now. Keep in mind that it can take a long time to compact a large data file.
Compact data file dialog

PSTNullFreeOnClose

If you want to force Outlook to return this free space every time that you close Outlook, you can add PSTNullFreeOnClose to the registry.

Press Windows key + R and type regedit in the Run dialog then press Enter to open the registry editor.

  1. Browse to the appropriate key for your version of Outlook.
  2. If the PST subkey does not exist, create it.
  3. Right click on PST key and choose New, DWORD.
  4. Type (or paste) PSTNullFreeOnClose as the Name.
  5. Double click on it and enter 1 as the Value.

For Outlook 2016/2019/365:
HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\PST
For Outlook 2013:
HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\PST
For Outlook 2010:
HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\PST
Outlook 2007:
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\PST
Outlook 2003:
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\PST
Outlook 2002:
HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\PST
Outlook 2000:
HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Outlook\PST


DWORD: PSTNullFreeOnClose
Value Data: 1 = compact on close, 0 = don’t compact

PSTNullFreeOnClose registry key

This key was introduced in an update for Outlook 2000 and works in all versions of Outlook that are updated with the latest service pack.

This key compacts both pst and ost files. With the value set to 1, deleted data is removed when you close Outlook. When it’s set to 0 or deleted, the data file will not be compacted on close.

Note that the first time you close Outlook after making this change, it may take a long time for Outlook to close.

Doit It For Me

If you don't want to edit the registry, we have reg files you can use.

Outlook 2016/2019/365 Outlook 2013
Outlook 2010 Outlook 2007

More Information

Outlook 2007 improvements in the February 2009 cumulative update
After installing Office 2007 SP2, Outlook takes a long time to close and Outlook.exe remains running in the background

How to Compact the Data File When you Close Outlook was last modified: February 15th, 2021 by Diane Poremsky
  • Twitter
  • Facebook
  • LinkedIn
  • Reddit
  • Print

Related Posts:

  • How to compact an Outlook data file (*.pst)
  • Are Deleted Items gone forever in Outlook?
  • Under certain conditions, Exchange server users testing Outlook 2013 d
    Outlook 2013 bug: Emptying Deleted Items deletes everything (Fixed)
  • Shared Mailboxes and the Deleted Items Folder

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
13 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

James (@guest_215535)
July 1, 2020 11:20 am
#215535

This registry setting only nulls free space within a PST or OST file. It doesn't actually remove the free space. You either have to manually compact the file or let Outlook do it automatically when a pre-defined threshold is met.

0
0
Reply
Mike (@guest_202596)
October 28, 2016 11:13 am
#202596

Interrelated questions about which files are targetted: How does the regedti ensure which/ all files are targeted? In other words: Does the code above apply to all PST/OST files everywhere, or do you have to specify a directory and/or a file?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Mike
October 28, 2016 5:04 pm
#202601

it works on the data file attached to your profile - it doesn't matter where it is stored on the hard drive. What the key does is trigger the compact process.

0
0
Reply
Dan Stevenson (@guest_191091)
May 28, 2015 8:48 am
#191091

Diane,

Thanks for your reply. In our case the .ost's are not corrupted, just very large because our employees like to save a lot of mail. I was hoping to find a way to have Outlook automatically compact on close because the built in background compaction does not seem to be working on any of the workstations I have checked so far. I am guessing it is because our workstations are almost never idle long enough for the background process to start.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Dan Stevenson
May 28, 2015 10:44 am
#191093

Yeah, it is because they aren't idle. If they use active screensavers, have them switch to one that is static. When they take a break, leave outlook open and lock the computer, don't sign off and on all day long.

0
0
Reply
Dan Stevenson (@guest_191075)
May 27, 2015 5:20 pm
#191075

Also tested this with Outlook 2010 connected to Exchange online accounts on two workstations so far and it did not work on either. Outlook takes longer to close but the .ost files never get smaller. Ran manual compact on both workstations and the difference in size of the .ost files afterwords was dramatic. Over 70% reduction in size. I wish there was a way to automatically compact .ost files in Outlook 2010 since we have a lot of workstations that I will have to manually compact the files.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Dan Stevenson
May 28, 2015 8:24 am
#191089

They usually recommend deleting and rebuilding the ost instead of trying to repair it - that would work for compact too. It's not bad if the ost is fairly small as it will sync fast. But it can cause network issues if the ost is large.

0
0
Reply
Costen (@guest_189797)
March 12, 2015 1:58 pm
#189797

This RegKey PSTNullFreeOnClose (set to 1) does not seem to work for OST (tested with Outlook 2010). Outlook seems to take more time closing (I see the icon in the status bar for far longer time, but no file size change). A manual compress works. Can anybody confirm that they've used PSTNullFreeOnClose successfully to compress the OST automatically when Outlook closes? Thank you! And, thank you Ms. Poremsky for your MS Office articles.

0
0
Reply
Lorne Rogers (@guest_183148)
April 26, 2014 9:16 am
#183148

Is there a way to do this for OST files instead of PST?

0
0
Reply
Diane Poremsky (@guest_183151)
Reply to  Lorne Rogers
April 26, 2014 10:52 pm
#183151

it's supposed to compact ost files too.

0
0
Reply
Mike Sun (@guest_179066)
September 4, 2013 7:01 am
#179066

yw - Cheers :)

0
0
Reply
Mike Sun (@guest_179064)
September 4, 2013 4:47 am
#179064

The "Do it for Me" reg files - 2007 and 2010 are swapped around i.e 2007 is for 2010 and vice versa...

0
0
Reply
Diane Poremsky (@guest_179065)
Reply to  Mike Sun
September 4, 2013 5:13 am
#179065

Oh, sorry about that. I'll get that fixed right now. Thanks for letting me know.

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 28 Issue 11

Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Subscribe to Exchange Messaging Outlook






Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • WeekMonthAll
  • Adjusting Outlook's Zoom Setting in Email
  • How to Remove the Primary Account from Outlook
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Move an Outlook Personal Folders .pst File
  • Save Sent Items in Shared Mailbox Sent Items folder
  • Create rules that apply to an entire domain
  • Outlook's Left Navigation Bar
  • Remove a password from an Outlook *.pst File
  • Use PowerShell to get a list of Distribution Group members
  • View Shared Calendar Category Colors
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Change Appointment Reminder Sounds
  • Messages appear duplicated in message list
  • Reset the New Outlook Profile
  • Delete Old Calendar Events using VBA
  • Use PowerShell or VBA to get Outlook folder creation date
  • Outlook's Left Navigation Bar
  • Contact's Display Bug
  • Use PowerShell to get a list of Distribution Group members
  • Edit Outlook’s Attach File list
Ajax spinner

Newest Code Samples

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

Format Images in Outlook Email

Set Outlook Online or Offline using VBScript or PowerShell

List snoozed reminders and snooze-times

Search your Contacts using PowerShell

Filter mail when you are not the only recipient

Add Contact Information to a Task

Process Mail that was Auto Forwarded by a Rule

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in Outlook for Windows.

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




Windows 10 Issues

  • iCloud, Outlook 2016, and Windows 10
  • Outlook Links Won’t Open In Windows 10
  • Outlook can’t send mail in Windows 10: error Ox800CCC13
  • Missing Outlook data files after upgrading Windows?

Outlook Top Issues

  • The Windows Store Outlook App
  • The Signature or Stationery and Fonts button doesn’t work
  • Outlook’s New Account Setup Wizard
  • Outlook 2016: No BCM
  • Exchange Account Set-up Missing in Outlook 2016

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Contact Tools

Data Entry and Updating

Duplicate Checkers

Phone Number Updates

Contact Management Tools

Diane Poremsky [Outlook MVP]

Make a donation

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Outlook Suggestion Box (UserVoice)

Slipstick Support Services

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Advertise | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2023 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment