• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • 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     15 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

Related Posts:

  • How to compact an Outlook data file (*.pst)
  • Error: Message archive has reached maximum size
  • Are Deleted Items gone forever in Outlook?
  • Recover messages deleted from .pst files

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
15 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

James
July 1, 2020 11:20 am

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
October 28, 2016 11:13 am

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
Author
Reply to  Mike
October 28, 2016 5:04 pm

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
May 28, 2015 8:48 am

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
Author
Reply to  Dan Stevenson
May 28, 2015 10:44 am

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
May 27, 2015 5:20 pm

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
Author
Reply to  Dan Stevenson
May 28, 2015 8:24 am

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
March 12, 2015 1:58 pm

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.

1
0
Reply
Jan
Reply to  Costen
December 8, 2024 3:59 am

It does not work with OST files. Outlook 2019 takes forever to close, preventing users from signing out. No disk space is freed and when the user has reminders open Outlook becomes unresponsive.

0
0
Reply
Diane Poremsky
Author
Reply to  Jan
December 8, 2024 8:07 pm

OST files tend to compact themselves, especially if you have the mailbox set to sync less than All in File > Account Settings > Account name & sync settings.

If you manually compact the file, does it shrink much?

If you are using an IMAP account, Outlook doesn't always close properly when you have an IMAP account in your profile and this can cause Outlook to have sync issues. There is a registry key to use as a workaround. If you don't want to edit the registry, I have a ready-to-use registry file available
https://www.slipstick.com/doit/AllowLOGOUT.reg

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Outlook\IMAP
DWORD: AllowLOGOUTWithoutOK
Value: 1

0
0
Reply
Lorne Rogers
April 26, 2014 9:16 am

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

0
0
Reply
Diane Poremsky
Reply to  Lorne Rogers
April 26, 2014 10:52 pm

it's supposed to compact ost files too.

0
0
Reply
Mike Sun
September 4, 2013 7:01 am

yw - Cheers :)

0
0
Reply
Mike Sun
September 4, 2013 4:47 am

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
Reply to  Mike Sun
September 4, 2013 5:13 am

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. 30 Issue 32

Subscribe to Exchange Messaging Outlook






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?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
Ajax spinner

Recent Bugs List

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

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

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

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

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.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

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

Other Microsoft 365 applications and services




New Outlook Articles

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

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

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

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

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

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 | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

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

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
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