If you’ve spent any time working with files or data—whether it’s in a spreadsheet, an enterprise database, or server logs—you’ve probably run into numbers that just don’t make immediate sense. File sizes like “8388608” or “10737418240” appear everywhere, but without some context, it’s tricky to see how they relate to your storage or daily tasks.
In this tutorial, I’ll walk you through several easy and reliable ways to convert bytes to gigabytes (GB) using PowerShell. These techniques will help you write reports that are easier to understand, automate checks on disk space, or just make raw data more human-friendly.
Understanding Data Size Units
Before we get to the scripts, let’s quickly revisit the basics. Computers store data in bytes, which are the building blocks for kilobytes (KB), megabytes (MB), gigabytes (GB), and beyond. Here’s the classic tech breakdown:
- 1 KB = 1,024 bytes
- 1 MB = 1,024 KB
- 1 GB = 1,024 MB
While some storage devices may advertise in the thousands (where 1 GB = 1,000,000,000 bytes), Windows and PowerShell usually stick to the “binary” system above, where each unit is a multiple of 1,024. Whenever you’re converting in PowerShell or writing scripts, keep this system in mind to avoid any confusion.
Check out Convert Bytes to Base64 String in PowerShell
PowerShell: Convert Bytes to GB
Now, let me show you different methods to convert bytes to GB in PowerShell.
Basic Conversion with Arithmetic Operators
At its core, converting bytes to gigabytes in PowerShell is a simple division task. Since there are 1,073,741,824 bytes in a GB, you can just divide your byte value by this number:
$bytes = 10737418240
$gb = $bytes / 1073741824
Write-Output $gb # Outputs 10But PowerShell actually makes this much easier with special constants. For example, 1GB is built into PowerShell and automatically equals 1,073,741,824 bytes. Use it directly:
$bytes = 10737418240
$gb = $bytes / 1GB
Write-Output $gb # Outputs 10Here is the exact output in the screenshot below:

These constants make code cleaner and save you from having to remember “the big numbers.”
Using PowerShell’s Built-in Constants
One of my favorite features in PowerShell is its built-in constants for modern units:
1KB= 1,024 bytes1MB= 1,048,576 bytes1GB= 1,073,741,824 bytes
With these, conversions stay readable and prevent accidental mistakes:
$bytes = 5368709120
$gb = $bytes / 1GB
Write-Output "Result: $gb GB"You can see the exact output in the screenshot below:

If you’re reading file sizes, disk usage, or reporting on large numbers, always use these constants to avoid errors and to keep code self-explanatory.
Read Get String Length in Bytes in PowerShell
Formatting the Output
Sometimes, the conversion gives you long decimal numbers—great for precision, but not always helpful in reports. For example:
$bytes = 4850000000
$gb = $bytes / 1GB
Write-Output $gb # Might output 4.51767349243164Tidy things up with formatting:
"{0:N2}" -f ($bytes / 1GB)
# Outputs 4.52 (shows two decimals)Or use Math functions for rounding:
[math]::Round($bytes / 1GB, 2)Make a Reusable Function
For any task you do often, create a little function, so that you can reuse it when you need it.
function Convert-BytesToGB {
param([long]$bytes)
return [Math]::Round(($bytes / 1GB), 2)
}
Write-Output (Convert-BytesToGB 3758096384) # Outputs 3.5Now you can reuse this across scripts, reports, or even on the fly in your PowerShell console.
Check out Measure-Object in PowerShell
Examples: Convert Bytes to GB in PowerShell
Here, I will show you some examples of converting bytes to gb in PowerShell.
1. Get File Size in GB
Here is an example that you can use to get a particular file size in GB using PowerShell.
$file = Get-Item "C:\Data\LargeFile.bak"
$sizeGB = [Math]::Round($file.Length / 1GB, 2)
Write-Output "$($file.Name) is $sizeGB GB"Great for analyzing backup files or export files.
2. Monitor Available Disk Space
Here is another example, that will show available disk space in GB using PowerShell.
Get-PSDrive -PSProvider FileSystem | ForEach-Object {
$usedGB = [Math]::Round($_.Used / 1GB, 2)
$freeGB = [Math]::Round($_.Free / 1GB, 2)
Write-Output "$($_.Name): $freeGB GB free, $usedGB GB used"
}Ideal for spot-checking server drives or automating routine checks.
3. List Folder Contents by Size (in GB)
Below is another example that you can use to check the folder size in GB in PowerShell.
Get-ChildItem "C:\Logs" | Select-Object Name,
@{Name="Size(GB)";Expression={[Math]::Round($_.Length / 1GB, 2)}}Now, sorting or reviewing large collections of files makes sense at a glance.
Conclusion
In this tutorial, I explained how to convert bytes to GB in PowerShell using various approaches. Also, we saw some real examples of converting bytes to GB in PowerShell. Please let me know if these examples are helpful to you.
You may also like the following tutorials:
- PowerShell Measure-Object 2 Decimal Places
- PowerShell Round to Nearest Whole Number
- PowerShell Round to 2 Decimal Places
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.