Skip to main content

How many Mastodon instances are out there?

Ever since I spun up my own Mastodon server and I've been watching my web logs just to see all the other unique instances that connect to mine. My personal server with only one user currently knows about ~1800 other servers. But there's got to be more than that out there, right? I thought so too. So I wrote a fairly simple bit of PowerShell that lets me crawl the reference tree from one server to the next and try and count all the instances on the internet.

Get-MastodonInstances.ps1

$instances = New-Object System.Collections.Generic.HashSet[string] -ArgumentList ([StringComparer]::OrdinalIgnoreCase)

$instances.Add("mastodon.social")
$newInstances = @("mastodon.social")

for ($i = 0; $i -lt $newInstances.Count; $i++) {
    $instance = $newInstances[$i]
    Write-Host "$i / $($newInstances.Count) ($instance)"
    
    $serverInstances = (Invoke-WebRequest `
            -Uri "https://$instance/api/v1/instance/peers" `
            -Method GET `
            -ErrorAction SilentlyContinue).Content |
    ConvertFrom-Json

    $unseenInstances = $serverInstances | Where-Object { ($_.IndexOf("*") -lt 0) -and $instances.Add($_) }
    $newInstances += $unseenInstances
}

$instances | Out-File -FilePath MastodonInstances.txt

$instances.Count

There are some caveats to this approach, of course. Some of the instances the script encountered were offline, some were not actually Mastodon, but other implementors of ActivityPub (Friendica, Pleroma, etc.), and some just didn't like me querying them anonymously. There is also the case where certain "social circles" have completely cut themselves off from the rest of the Fediverse. I'll never know about those servers.

My script has been running for about an hour now, and it's only now querying the ~2700th host, and has added ~44,000 to the backlog. It'll be a while before it finishes. Offline domains slow it down a lot while waiting for the timeout. I suppose I could have worked in multi-threading, but this was just a quick-and-dirty experiment. I'll update this post if and when it ever comes up with a final number.