[[File:Hostile and Peaceful.png|thumb|A naturally spawned [[creeper]] and [[chicken]]]]
[[Mob spawning]] is how both passive and hostile mobs are created. 

== Mob spawning on chunk generation ==
{{Exclusive|Java|section=1|customtext=Only mobs {{in|Java}} can spawn with [[world generation|chunk generation]]}}

=== Animals ===
{{IN|Java}} many animals generate upon initial chunk creation. These spawns occur only once per chunk. They are not affected by the {{Cmd|/gamerule doMobSpawning}} command.

One in ten newly-generated [[Chunk|chunks]] attempts to generate animal [[Mob|mobs]], usually in packs of up to 4 of the same species. The spawn attempt always starts on top of the highest available block in a randomly chosen column within the chunk. The chosen position must not be a solid block for the animals to generate. Once the starting position is chosen for a chunk, a second position is chosen in a 9×9 block area around the starting position. Blocks toward the center of the 9×9 area are more likely to be chosen than blocks toward the edge. The block does not need to be a [[grass block]] nor does it need to be illuminated as it does with [[mob spawning]]. If an animal can spawn at the second position, it does so. The second position becomes the first position, and a new second position is chosen like before in a 9×9 area. This process can repeat until each chunk has attempted to spawn 1–4 mobs.

{{IN|Bedrock}} animals do not spawn during chunk generation, but they continually attempt to spawn everywhere as part of the environmental spawning algorithm, according to their spawn weights, biome tags, and block requirements (see Bedrock Edition under Spawn Cycle, below).

There are 2 types of animals: common animals and biome-specific animals.

; Common animals

Common animal mobs do not spawn in [[desert]], [[badlands]], [[beach]], [[snowy plains]], [[river]], [[ocean]], or [[mushroom fields]] biomes.
{| class="wikitable"
!Mobs
!Weight
!Group size
|-
|{{EntityLink|Sheep}}
|6
|4
|-
|{{EntityLink|Chicken}}
|5
|4
|-
|{{EntityLink|Pig}}
|5
|4
|-
|{{EntityLink|Cow}}
|4
|4
|}

; Biome-specific animals

Some animal mobs spawn only in specific biomes.{{more info|There are many Y-axis limits for spawning, these should be mentioned}}
{| class="wikitable" data-description="Biome-Specific Mob"
!Mobs
!Biome
!Weight
|-
|
* {{EntityLink|Axolotl}}
|
* {{BiomeLink|Lush Caves}}
|4
|-
|
* {{EntityLink|Cod}}
|
* {{BiomeLink|Ocean}}
* {{BiomeLink|Lukewarm Ocean}}
* {{BiomeLink|Cold Ocean}}
* {{BiomeLink|Frozen Ocean}}
|75
|-
|
* {{EntityLink|Dolphin}}
|
* {{BiomeLink|Ocean}}
* {{BiomeLink|Warm Ocean}}
* {{BiomeLink|Lukewarm Ocean}}
* {{BiomeLink|Cold Ocean}}
|7
|-
|
* {{EntityLink|Donkey}}
|
* {{BiomeLink|Plains}}
|1
|-
|
* {{EntityLink|Frog}}
|
* {{BiomeLink|Swamp}}
* {{BiomeLink|Mangrove Swamp}}
|2 to 5 in swamps and mangrove swamps
|-
|
* {{EntityLink|Fox}}
|
* {{BiomeLink|Taiga}}
* {{BiomeLink|Snowy Taiga}}
* {{BiomeLink|Old Growth Pine Taiga}}
|8
|-
|
* {{EntityLink|Glow Squid}}
|
* {{BiomeLink|Ocean}}{{more info|Glow squids can spawn in any biome}}
|2-4
|-
|
* {{EntityLink|Goat}}
|
* {{BiomeLink|Frozen Peaks}}
* {{BiomeLink|Jagged Peaks}}
* {{BiomeLink|Snowy Slopes}}
|3
|-
|
* {{EntityLink|Hoglin}}{{only|Bedrock|short=y}}
|
* {{BiomeLink|Crimson Forest}}
|20
|-
|
* {{EntityLink|Horse}}
|
* {{BiomeLink|Savanna}}
* {{BiomeLink|Plains}}
|4 in plains
1 in savanna
|-
|
* {{EntityLink|Llama}}
|
* {{BiomeLink|Savanna}}
* {{BiomeLink|Windswept Hills}}
|8 in savanna
5 in windswept hills
|-
|
* {{EntityLink|Mooshroom}}
|
* {{BiomeLink|Mushroom Fields}}
|8
|-
|
* {{EntityLink|Ocelot}}
* {{EntityLink|Parrot}}
|
* {{BiomeLink|Jungle}}
* {{BiomeLink|Bamboo Jungle}}
|30 for ocelots
40 for parrots
|-
|
* {{EntityLink|Panda}}
|
* {{BiomeLink|Jungle}}
* {{BiomeLink|Bamboo Jungle}}
|10 in regular jungle
40 in bamboo jungle
|-
|
* {{EntityLink|Polar Bear}}
|
* {{BiomeLink|Snowy Plains}}
* {{BiomeLink|Frozen Ocean}}
* {{BiomeLink|Frozen River}}
|1 (5 in frozen oceans)
|-
|
* {{EntityLink|Pufferfish}}
* {{EntityLink|Tropical Fish}}
|
* {{BiomeLink|Warm Ocean}}
* {{BiomeLink|Lukewarm Ocean}}
* {{BiomeLink|Deep Lukewarm Ocean}}
|25 for pufferfish
75 for tropical fish
|-
|
* {{EntityLink|Rabbit}}
|
* {{BiomeLink|Desert}}
* {{BiomeLink|Taiga}}
* {{BiomeLink|Old Growth Pine Taiga}}
* {{BiomeLink|Snowy Taiga}}
* {{BiomeLink|Snowy Plains}}
* {{BiomeLink|Frozen Ocean}}
* {{BiomeLink|Frozen River}}
* {{BiomeLink|Snowy Beach}}
* {{BiomeLink|Legacy Frozen Ocean}}
* {{BiomeLink|Flower Forest}}
|4 (20 in flower forests)
|-
|
* {{EntityLink|Salmon}}
|
* {{BiomeLink|River}}
* {{BiomeLink|Cold Ocean}}
* {{BiomeLink|Frozen Ocean}}
* {{BiomeLink|Lukewarm Ocean}}
|26 in oceans
16 in rivers
|-
|
* {{EntityLink|Squid}}
|
* {{BiomeLink|Ocean}}
* {{BiomeLink|River}}
|8
|-
|
* {{EntityLink|Strider}}
|
* {{BiomeLink|Nether Wastes}}
* {{BiomeLink|Crimson Forest}}
* {{BiomeLink|Soul Sand Valley}}
* {{BiomeLink|Basalt Deltas}}
* {{BiomeLink|Warped Forest}}
|20
|-
|
* {{EntityLink|Turtle}}
|
* {{BiomeLink|Beach}}
|8
|-
|
* {{EntityLink|Wolf}}
|
* {{BiomeLink|Taiga}} (all variants)
* {{BiomeLink|Forest}} (all variants)
* {{BiomeLink|Windswept Hills}} (all variants)
|8 in taigas
5 in forests and windswept hills
|}
Randomness for animal spawning is derived from the [[Seed (world generation)|world seed]], which means that ''worlds with the same seed'' always generate chunks with ''the same animals in the same places''.

=== Monsters ===
Monsters cannot spawn when the [[difficulty]] is set to Peaceful (except for [[Piglin|piglins]] and [[Hoglin|hoglins]]). At any higher setting they spawn when block light level is 0. The player cannot sleep when a monster (other than hoglins, [[Slime|slimes]]{{Only|java|short=1}} [[Magma cube|magma cubes]]{{Only|java|short=1}} and non-hostile [[Zombified piglin|zombified piglins]]{{Only|java|short=1}}) is within ten blocks, even if the monster has no path to the player.

; Common monsters

Common monster mobs can spawn in almost any biome in the Overworld (except for [[mushroom fields]] or [[deep dark]]). They can spawn on the surface ''and'' underground. The weight determines the spawn rate in the ''Bedrock Codebase''.
{| class="wikitable"
!Mobs
!Weight
!Group size
|-
|{{EntityLink|Zombie}}
|100
|2-4
|-
|{{EntityLink|Creeper}}
|100
|Individually
|-
|{{EntityLink|Skeleton}}
|80
|1-2
|-
|{{EntityLink|Spider}}
|100
|Individually
|-
|{{EntityLink|Enderman}}
|10
|1-2
|-
|{{EntityLink|Witch}}
|5
|Individually
|-
|{{EntityLink|Zombie Villager}}
|5
|Individually
|}<!--Slime is listed below as it spawns only in swamps and slime chunks, and zombie villager is not because it is described at [[#Other mobs]] and [[#Other types of spawning]]-->

; Biome-specific monsters

Some monsters spawn only in specific biomes.
{| class="wikitable" data-description="Biome Specific Mob"
!Mobs
!Biome
|-
|
* {{EntityLink|Bogged}}
|
* {{BiomeLink|Swamp}}
* {{BiomeLink|Mangrove swamp}}
|-
|
* {{EntityLink|Drowned}}
|
* {{BiomeLink|Ocean}} (all variants)
* {{BiomeLink|River}} (all variants)
* {{BiomeLink|Dripstone Caves}}
|-
|
* {{EntityLink|Ghast}}
|
* {{BiomeLink|Nether Wastes}}
* {{BiomeLink|Soul Sand Valley}}
* {{BiomeLink|Basalt Deltas}}
|-
|
* {{EntityLink|Hoglin}}{{only|java|short=y}}
|
* {{BiomeLink|Crimson Forest}}
|-
|
* {{EntityLink|Husk}}
|
* {{BiomeLink|Desert}} (all variants)
|-
|
* {{EntityLink|Magma Cube}}
|
* {{BiomeLink|Nether Wastes}}
* {{BiomeLink|Basalt Deltas}}
|-
|
* {{EntityLink|Slime}}
|
* {{BiomeLink|Swamp}}
* {{BiomeLink|Mangrove swamp}}
|-
|
* {{EntityLink|Stray}}
|
* {{BiomeLink|Snowy Plains}}
* {{BiomeLink|Ice Spikes}}
* {{BiomeLink|Frozen River}}
* {{BiomeLink|Frozen Ocean}} (all variants)
|-
|
* {{EntityLink|Piglin}}
* {{EntityLink|Zombified Piglin}}
|
* {{BiomeLink|Nether Wastes}}
* {{BiomeLink|Crimson Forest}}
|}

=== Other mobs ===
{{IN|Java}} these mobs still spawn if the {{cmd|gamerule doMobSpawning}} command is set to <code>false</code>, because they spawn as part of structure generation. {{IN|Bedrock}} nothing spawns if the {{cmd|gamerule doMobSpawning}} command is set to <code>false</code>.

; Passive and neutral mobs

{| class="wikitable" data-description="Other animals"
!Mob
!Structure generation
|-
|
* {{EntityLink|Allay}}
|Allays can spawn up to in 1-3 groups in a {{EnvLink|Pillager Outpost|pillager outpost}} and a {{EnvLink|woodland mansion}}.
|-
|
* {{EntityLink|Black Cat}}
|A single black cat spawns within or around a {{EnvLink|swamp hut}} upon generation.
|-
|
* {{EntityLink|Camel}}
* {{EntityLink|Cat}}
* {{EntityLink|Cow}}
* {{EntityLink|Horse}}
* {{EntityLink|Pig}}
* {{EntityLink|Sheep}}
|Generate as part of the {{EnvLink|village}} generation.
Specific animals spawn as part of specific [[Village/Structures 1.14|village structures]]: Animal pens (cow, sheep, pig, or horse), stables (horse, cow, or pig), butcher's houses (pig, cow, or sheep), and shepherd's houses (sheep).
|-
|
* {{EntityLink|Iron Golem}}
|Spawn from {{EnvLink|Pillager Outpost|pillager outposts}}.
Generate as part of the {{EnvLink|village}} generation.
|-
|
* {{EntityLink|Villager}}
|Generate as part of the {{EnvLink|village}} generation.
Each villager spawns in a house with a bed.
|}

; Hostile mobs

{| class="wikitable" data-description="Other monsters"
!Mob
!Structure generation
|-
|
* {{EntityLink|Drowned}}
|Generate as part of some {{EnvLink|underwater ruins}}.{{only|java|short=1}}
|-
|
* {{EntityLink|Elder Guardian}}
* {{EntityLink|Guardian}}
|Generate as part of an {{EnvLink|ocean monument}}.
|-
|
* {{EntityLink|Ender Dragon}}
|Created in {{EnvLink|the End}} when the dimension is created. The ender dragon can also be respawned by placing [[End crystal|end crystals]] on the [[exit portal]].
|-
|
* {{EntityLink|Evoker}}
* {{EntityLink|Vindicator}}
|Generate as part of a {{EnvLink|woodland mansion}}.
|-
|
* {{EntityLink|Pillager}}
|Spawn from {{EnvLink|Pillager Outpost|pillager outposts}}.
|-
|
* {{EntityLink|Shulker}}
|Generate as part of {{EnvLink|End City|end cities}}.
|-
|
* {{EntityLink|Witch}}
|A single witch spawns within a {{EnvLink|swamp hut}} upon generation.
|-
|
* {{EntityLink|Zombie Villager}}
|Generate as a part of an {{EnvLink|igloo}} if it generates with a [[Igloo#Structure|basement]].
Can spawn as part of {{EnvLink|Village|zombie village}} generation, where they never despawn naturally.
|}

== Spawn cycle ==

=== ''Java Edition'' ===
Mobs are broadly divided into seven categories: hostile, passive, water creature ([[Squid|squids]] and [[Dolphin|dolphins]]), underground water creature ([[Glow squid|glow squids]]), axolotls, water ambient (all 4 types of [[fish]]), and ambient ([[bat]]). Most mobs have a spawning cycle once every game [[tick]] ({{frac|1|20}} of a second), but passive mobs have only one spawning cycle every {{convert|400|game tick|second}}. Because of this, where conditions permit, hostile mobs spawn frequently, but passive mobs (animals) spawn rarely. Most animals spawn within chunks when they are [[Spawn#Natural generation|generated]].

Mobs spawn naturally within chunks that have a player horizontally within 128 blocks of the [[chunk]] center.<!--1.19.2: ServerChunkCache::tickChunks calls ChunkMap::anyPlayerCloseEnoughForSpawning() before calling NaturalSpawner::spawnForChunk() (and ServerLevel::tickChunk(), for that matter).--> When there are multiple players, mobs can spawn within the given distance of ''any'' of them. However, hostile mobs (and some others) that move farther than 128 blocks from the nearest player despawn instantly, so the mob spawning area for such mobs is more-or-less limited to spheres with a radius of 128 blocks, centered at each player.

==== ''Java Edition'' mob cap ====
There are two caps, a global cap and a per-player cap. Note the [[#Spawn costs|spawn density]] mechanism may also be considered a "cap" of sorts, but takes effect later in the spawning process.

The mob caps are checked once for each spawn-eligible chunk. Spawn for the chunk may take the total number of mobs over the cap.

The caps for each mob category are as follows:
{| class="wikitable"
!Mob category
!Cap
|-
|Monster
|70
|-
|Creature
|10
|-
|Ambient (bats)
|15
|-
|Axolotls
|5
|-
|Underground water creature (glow squids)
|5
|-
|Water creature (squids, dolphins)
|5
|-
|Misc
| -1
|}
The "misc" category is used only by entities that are not mobs, do not spawn naturally, and/or following different spawning rules than other mobs. As such the mob cap has no bearing on mobs of this category. The global mob cap affects only environmental mob spawning, and does not affect mobs spawned through breeding, spawn eggs, the /summon command, monster spawners, or any other type of mob spawning.

; Global mob cap

All non-[[Spawn#Java persistent mobs|persistent]] loaded mobs are counted against the global cap, including those in chunks not in range of a player or eligible for spawns. The cap is scaled by the total number of chunks within a 17×17 chunk square around any player. The cap is then scaled as <code>globalCap = mobCap &#xD7; chunks ÷ 289</code>. Because chunks that are in the range of multiple players are counted once, more chunks and higher mob caps result from the players spreading out.

; Per-player mob cap

Each non-[[Spawn#Java persistent mobs|persistent]] mob in a chunk that has its center within 128 blocks horizontally of a player is counted toward that player's per-player mob cap. For each chunk, spawns are only allowed if at least one player has that chunk in range and has not reached their per-player mob cap.

==== Pack spawning ====
[[File:Spawning_science.jpg|thumb|Example of a mob pack spawning. The mob spawning area is shaded blue. The yellow figures represent the actual positions that mobs could spawn in after checking the environment. Note that the mobs can spawn inside torch and ladder blocks. But they can't spawn on top of glass because it is not opaque. The red cube is the center of the pack.]]
[[File:Spawning_requirements.png|thumb|Requirements for the spawning location of individual mobs.]]
For each spawning cycle, attempts are made to spawn ''packs'' of mobs per ''each'' eligible chunk. An eligible chunk is determined by the same check for which chunks are [[Random tick|random ticked]]. A random location in the chunk is chosen to be the center point of the pack. The X and Z coordinates are chosen completely at random, while the Y coordinate is a random coordinate between the block above the highest block in the column and -64. This makes lower maximum elevations a strong way to increase spawn rates and is the reason why perimeters are so effective. If the block in which a pack spawn occurs is an opaque full cube, further pack spawn attempts are canceled. There are a maximum of 3 pack spawn attempts per mob category.

Before the attempt to spawn each mob in the pack, the position is offset by ±5 (triangular distribution) on the X and Z axes. Thus, while the pack can be spread out up to 40 blocks from the initial position for a pack size of 4, it's much more likely they'll be closer to the center. Approximately 85% of spawns are within 5 blocks of the pack center, and 99% within 10 blocks of the center. Mobs spawn with the lowest part of their body ''inside'' this area.

All mobs within a pack are the same species. The species for the entire pack is chosen randomly, but based on a weight system from those eligible to spawn at the location of the first spawn attempt in the pack. For later mob spawn attempts in the pack, if the selected species cannot spawn at the location (e.g. due to being in a different biome or structure) then that attempt fails.

The game checks on each spawn if the number of mobs that have been spawned for the pack is equal to the max spawn attempts, as well as the location's spawn potential.

; Pack spawn size

Pack spawn attempts max out at:

* 8 wolves, cod, and tropical fish
* 6 horses and donkeys
* 1 ghast
* 4 for any other mob

When the max pack size is less than the number of possible spawn attempts, some spawns attempts fail, but are seen more commonly in practice. Based on the number of mobs that have been successfully spawned. If the max pack size is greater than the number of spawn attempts, one gets only the number of spawns from the spawn attempts. Some mobs have a minimum and max pack size, meaning there is an even chance for any number of spawn attempts between them occurring.

* For [[Zombie villager|zombie villagers]], [[drowned]], [[Pillager|pillagers]], [[Donkey|donkeys]] in [[savanna]] biomes, [[Parrot|parrots]] in [[Jungle|jungles]] excluding [[bamboo jungle]] and jungle, cats in [[Swamp hut|swamp huts]] and [[Witch|witches]], it is 1.
* For parrots in [[Bamboo jungle|bamboo jungles]] and [[Jungle|jungles]], [[Polar bear|polar bears]], [[Squid|squids]] in [[Lukewarm ocean|lukewarm oceans]], [[Panda|pandas]] and [[Dolphin|dolphins]], it is 1-2.
* For donkeys in [[plains]] biomes, ocelots and pufferfish, it is 1-3.
* For [[endermen]] except in [[the End]] and in [[nether wastes]], and [[Squid|squids]] except in [[Lukewarm ocean|lukewarm oceans]], it is 1-4.
* For [[Rabbit|rabbits]] and [[Blaze|blazes]], it is 2-3.
* For [[Guardian|guardians]], [[Fox|foxes]], [[Zombified piglin|zombified piglins]] in [[Crimson forest|crimson forests]] and [[Strider|striders]], it is 2-4.
* For [[Turtle|turtles]], it is 2-5.
* For [[Horse|horses]], it is 2-6.
* For [[Piglin|piglins]] and [[Hoglin|hoglins]] in [[Crimson forest|crimson forests]], it is 3-4.
* For [[cod]] it is 3-6.
* For [[Llama|llamas]], it is 4-6.
* For [[Mooshroom|mooshrooms]], it is 4-8.
* For [[Wither skeleton|wither skeletons]] and [[Skeleton|skeletons]], in nether fortresses, it is 5.
* For [[Bat|bats]] and [[tropical fish]], it is 8.
* For every other mob, it is 4.

; Pack spawn location

For all dimensions, structure-based spawns take priority over biome for hostile spawns. This means that in a [[swamp hut]], [[pillager outpost]], [[nether fortress]] (outer bounding box only when there is [[nether bricks]] below it{{only|java|short=1}}), and [[ocean monument]], one sees only the corresponding hostile mobs for that structure within that structure.

In the [[Overworld]], this depends on the location:<!--Biome specific Animal mobs moved to table above (at #Natural Spawning section)-->

* [[Jungle]] biomes have a higher chance to spawn [[Chicken|chickens]].{{only|java}}
* [[Badlands]] biomes spawn only hostile mobs, [[Armadillo|armadillos]] and [[Bat|bats]].
* [[River]] and [[frozen river]] can spawn only [[drowned]], squid, and salmon underwater.<!--monsters just spawn from nearby biomes-->
* [[Ocean]] biomes do not spawn passive mobs. They spawn [[drowned]], and the other hostile mobs. [[Frozen ocean|Frozen oceans]] do not spawn dolphins, but do spawn [[Polar bear|polar bears]].
* [[Snowy plains]] biomes do not spawn animals other than [[Polar bear|polar bears]] and [[Rabbit|rabbits]].
* [[Swamp hut|Swamp huts]] spawn only [[Witch|witches]], [[Cat|cats]], and bats.
* [[Ocean monument|Ocean monuments]] spawn [[Guardian|guardians]], other water mobs and bats.
* [[Pillager outpost|Pillager outposts]] spawn [[Pillager|pillagers]], other passive mobs and bats.
* All other overworld biomes spawns common animals and common monsters, as well as slimes, dependent on spawn conditions.

In [[the Nether]]:

* [[Skeleton|Skeletons]], [[Wither skeleton|wither skeletons]], [[Magma cube|magma cubes]], [[Zombified piglin|zombified piglins]], and [[Blaze|blazes]] spawn within [[Nether fortress|nether fortresses]].
* [[Ghast|Ghasts]] spawn in [[nether wastes]], [[soul sand valley]] and [[basalt deltas]].
* Zombified piglins and piglins can spawn in nether wastes, while magma cubes spawn primarily in [[basalt deltas]] and sometimes in nether wastes.
* Ghasts, magma cubes and hoglins spawn regardless of light level.
* [[Hoglin|Hoglins]] and [[Piglin|piglins]] spawn at a higher rate anywhere in the [[crimson forest]] biome.
* [[Endermen]] spawn more frequently in the [[warped forest]] biome, but not in the crimson forest.
* [[Skeleton|Skeletons]] and [[Ghast|ghasts]] spawn more frequently in the [[soul sand valley]] biome.

==== Spawn conditions ====
Whether a spawn condition fails differs from the above determination if the game tries to spawn them in that biome. For example, dolphins can have pack spawns that occur inside of frozen ocean and deep frozen ocean biomes, but no other biomes. These rules apply to variants of the same mob, such as baby zombies and jockeys.

Each individual spawn attempt succeeds only if ''all'' of the following conditions are met:

* There must be no players or the world spawn point within a 24 radius block distance (spherical) of the spawning block
* The number of loaded mobs of that type must be less than the mob cap for that type. (I.e. the corresponding mobcap must not be full)
* The mob's collision box upon spawning must not collide with another collision box. A mob cannot spawn inside of anything that would collide with it upon spawning.
* The mob's collision box must not intersect with a solid block.
* For all mob types excluding passives and fish, spawns fail unless within a 128 radius block sphere around the player. For fish, spawns fail unless within a 64 block radius of the player.<ref name="20w10a">{{snap|20w10a|March 4, 2020}}</ref>
* {{cmd|gamerule doMobSpawning}} is <code>true</code>
* For non-aquatic mobs, the spawning block and the block above that cannot be [[Rail|rails]], [[Powered rail|powered rails]], [[Detector rail|detector rails]], [[Activator rail|activator rails]], [[Redstone components#Power components|redstone power components]], wither roses (except for wither skeletons) or sweet berry bushes (except for foxes).

; Hostile mobs

* The difficulty must not be Peaceful, excluding piglins and hoglins
** This also affects ocelots<ref>{{bug|MC-1788}}</ref>
* For all hostiles other than guardians, drowned, and phantoms:
** the block directly below it must have a solid, opaque, top surface (this includes top [[Slab|slabs]], upside-down [[stairs]], and others) or be [[soul sand]] or a [[slime block]].
** the block directly below it must not be [[bedrock]], [[barrier]], or any type of trapdoor or glass.
** The mob's collision box must not collide with any liquid.
** The block above the spawning block must be [[transparent]].<!--This means that you can block spawns of mobs that have collisions in the block above the spawning block, which is often used in spider farms.-->
** The mob must be immune to the damaging effects of the spawning block and the block directly below it. For instance, if the block directly below the spawning block is a [[magma block]], the mob must be immune to fire damage. If the spawning block contains a [[wither rose]], the mob must be immune to wither damage. (Currently, this is only true for wither skeletons).

The basic rules for spawning are as follows:

* In the Overworld, block light level must be 0 and sky light must be 7 or below (which it always is inside a cave).
* In the Nether, block light level must be 11 or less. Sky light is always 0 in the Nether.
* In the End, block light level must be 0. Sky light is always 0 in the End.

When doing the light check in the Overworld and End, the spawn chances are randomized and a spawn only occurs if the light level is less than or equal to a random number between 0 and 7. In the Nether, as long as the light level is below 11, the spawn is allowed.

Some mobs have some additional rules in addition to the ones above.
{| class="wikitable"
! scope="col" |Mob
! scope="col" |Rules
|-
|{{EntityLink|Blaze}}
|
* Spawns only in nether fortresses
|-
|{{EntityLink|Drowned}}
|
* Spawning block and block below must be water
* In rivers, has {{frac|1|15}} chance to spawn
* In oceans, has {{frac|1|40}} chance to spawn and must be 5 block below sea level
|-
|{{EntityLink|Ghast}}
|
* 95% chance of spawn failure.
|-
|{{EntityLink|Guardian}}
|
* The spawning block and the block below must be water, including waterlogged blocks and bubble columns.
* 95% chance of failure if the spawning block has sky exposure ([[Guardian#Spawning|details]]).
|-
|{{EntityLink|Hoglin}}
|
* Cannot spawn on nether wart block
|-
|{{EntityLink|Husk}}
|
* The location of the spawn must have sky access
|-
|{{EntityLink|Magma Cube}}
|
* Cannot spawn on liquid
|-
|{{EntityLink|Ocelot}}
|
* Spawn has a {{frac|1|3}} chance of failure
* Can spawn on leaves
|-
|{{EntityLink|Piglin}}
|
* Cannot spawn on nether wart block
|-
|{{EntityLink|Skeleton}} (nether fortress)
|
* There is an 80% chance of spawning a [[wither skeleton]] instead{{verify}}
|-
|{{EntityLink|Slime}} (swamp biome)
|
* the spawning block must be in a swamp biome
* the spawning block be on level 51 through 69 inclusive
* chance of failure based on [[Difficulty#Moon phase|the phase of the moon]]
* 50% chance of failure
|-
|{{EntityLink|Slime}} (slime chunks)
|
* the spawning block is below level 40.
* 90% chance of failure.
|-
|{{EntityLink|Stray}}
|
* The location of the spawn must have sky access
|-
|{{EntityLink|Wither Skeleton}}
|
* Spawns only in Nether fortresses
|-
|{{EntityLink|Zombified Piglin}}
|
* Cannot spawn on nether wart block
|}

; Passive mobs

* The mob's collision box must not collide with any liquid.
** if it is not a [[strider]], the light level of the spawning block must be 9 or brighter.
*** If it is a [[mooshroom]], then...
**** the block directly below the spawning block must be [[mycelium]].
*** If it is a [[turtle]], then...
**** the block directly below the spawning block must be [[sand]].
**** the spawning block must be y-level 66 or lower.
*** If it is a [[parrot]], then...
**** the block directly below the spawning block must either be [[grass block]], [[leaves]], [[log]], or [[air]].
*** If it is a [[rabbit]], then...
**** the block directly below the spawning block must either be [[grass block]], [[snow block]], [[snow]]<ref name="snow">Only 8 levels, since only blocks with solid top surfaces are spawnable. See {{bug|MC-202376}}</ref>, or [[sand]].
*** If it is a [[wolf]], then...
**** the block directly below the spawning block must either be [[grass block]], [[snow block]], [[snow]], [[podzol]], or [[coarse dirt]]<ref name="snow" />.
*** If it is a [[fox]], then...
**** the block directly below the spawning block must either be [[grass block]], [[snow block]], [[snow]]<ref name="snow" />, [[podzol]], or [[coarse dirt]].
*** If it is a [[polar bear]] spawning in a [[frozen ocean]] or deep frozen ocean biome, then...
**** the block directly below the spawning block must be [[ice]].
*** If it is a [[goat]], then...
**** the block directly below the spawning block must either be [[stone]], [[snow block]], [[snow]]<ref name="snow" />, [[packed ice]], or [[gravel]]..
*** If it is an armadillo, then...
**** the block directly below the spawning block must be grass block, terracotta, red sand, or coarse dirt
*** If it is a frog, then...
**** the block directly below the spawning block must be a grass block, mud, mangrove root, or muddy mangrove roots.
*** For all others then...
**** the block directly below the spawning block must be a [[grass block]].
** If it is a [[strider]], then...
*** Spawn attempts with lava above check upward as long as there is still lava for if they can successfully spawn in a lava block with air on top.

; Aquatic mobs

* The spawning block must be water
** For [[cod]], [[salmon]], [[pufferfish]], [[tropical fish]], [[squid]] or [[dolphin]]:
*** the block directly below the spawning block must be water
*** the block directly above the spawning block must be water and cannot be waterlogged
*** the spawning block must be between level 50 and 63, inclusive. This does not apply to [[tropical fish]] spawning in lush caves
** If it is a [[glow squid]], then...
*** the light level must be 0
*** the spawning block must be level 30 or lower
** If it is an [[axolotl]], then...
*** the block directly above the spawning block must not be a solid block
*** the block directly below the spawning block must be [[clay]]

; Ambient mobs

* The mob's collision box must not collide with any liquid.
** If it is a [[bat]], then...
*** the spawning block must be at level 62 or below.
*** the block directly below it must have a solid, opaque, top surface.
*** the block directly below it must not be [[bedrock]], [[barrier]], or any type of trapdoor or glass.
*** If the real-time day is between October 20 and November 3, then the light level must be 7 or darker. Otherwise, the light level must be 4 or darker.

If all of these conditions are met then the mob is spawned.

; {{Visible anchor|Spawn costs}}

[[File:Spawning_potential_as_visualized_with_minecraft.png|thumb|Locations that do not have spawning potential reliant spawns are marked by wart blocks or netherrack]]
The [[warped forest]] and [[soul sand valley]] biomes introduced a new mechanic to limit the amount of mobs that naturally spawn in them. The spawn cost (also called '''spawn potential''' or '''spawn density''') takes on a value for each block in the biome. Certain mobs increase that value by some number ("charge") divided by their distance to the block. If a new spawn attempt would bring the "potential" of the spawning block above a certain threshold, the spawn attempt is canceled. This results in mobs not spawning too close to one another in these biomes, and new spawns in the area are completely blocked long before the full mobcap of 70 hostile mobs is ever reached.

More specifically, a mob may be spawned at a location if <code>sum( existing mob's charge ÷ distance to mob ) × new mob's charge < new mob's maximum potential</code>.<!--See net.minecraft.world.level.PotentialCalculator--> While the code allows for different mobs to have different charges and maximum potential, all checked mobs have the same charge and maximum potential within both the [[warped forest]] and the [[soul sand valley]].

Which mobs contribute to the charge, how much they add, and what the maximum potential is are all biome-specific. Mobs carry charge according to their current biome, and affect spawning in an adjacent biome even if they would not contribute a charge if in that biome. For example, striders in a soul sand valley affect enderman spawns in an adjacent warped forest, even though striders in the warped forest itself do not.

Due to the limited total number of mobs in soul sand valleys and warped forests, a larger-than-usual amount of mobs spawn in any space outside of these biomes, including in nether fortresses.

; Notes

* Buildings surrounded by air spawn more mobs inside than underground rooms because packs that spawn outside of the building can spawn mobs inside it. The mob caps tend to be reached in seconds.
* If the player's view distance or the server view distance in multiplayer is at 9 or below, mob spawning is severely reduced (or they despawn too quickly), and may result in the player encountering no mobs at all. Set the view distance to 10 or higher to ensure mobs spawn correctly.

=== ''Bedrock Edition'' ===
Environmental spawning {{in|be}} shares broad similarities to natural spawning in ''[[Java Edition]]'': mobs spawn in a radius around the player subject to block conditions, lighting conditions, biome conditions, naturally generated structure conditions, and caps. Many mobs spawn in groups (called "packs" in Java and "herds" in Bedrock). One notable difference from ''Java Edition'' is that most animals can spawn at light level 7 or higher rather than 9 or higher.

There are two types of environmental spawns: cluster spawns and structure spawns. Structure spawns reproduce specific types of mobs at specific locations within certain naturally generated structures, such as nether fortresses, swamp huts, etc. Cluster spawns account for all other types of environmental spawns, including mobs that spawn individually (i.e. not in a herd of 2 or more). Both types of environmental spawns follow the same rules for spawn conditions and mob caps, except that structure spawns can exceed the monster population cap by 1 (see below).

Mob spawning in bedrock edition happens within a spherical shell 24-44 blocks away from the player on [[simulation distance]] 4. It happens in a quasi-spherical shell 24-128 blocks away from the player, restricted by a simulation distance and/or to roughly 96 blocks horizontally, on simulation distances 6 and higher. This means that mobs can spawn directly above or below the player (for example, phantoms in the sky or zombies underground). Mobs can spawn only in chunks that are being ticked. There is a {{frac|11|2000}} chance of the mob spawning algorithm attempting to run per chunk, per tick.

==== ''Bedrock Edition'' mob cap ====
There are three mob caps that affect environmental spawning: a global mob cap, population control caps for general mob types, and density caps for specific mob types. The global mob cap is set at 200 regardless of difficulty. The global mob cap affects only environmental mob spawning, and does not affect mobs spawned through [[breeding]], [[Spawn egg|spawn eggs]], the {{cmd|summon}} command, [[Monster spawner|monster spawners]], or any other type of mob spawning. Chickens created by thrown or dispensed eggs are counted in the global mob cap. Only mobs that have spawn rules count toward the global cap (i.e. armor stands and minecarts do not take up cap space). In addition, mobs that are within ticking areas (both those around players and those set manually using the {{cmd|tickingarea}} command) count toward the global mob cap; mobs not ticked do not count toward the global mob cap.

The population control caps limit how many mobs of each type and category can spawn within a 9 chunk by 9 chunk square region surrounding the chunk in which the spawn attempt is made. Mobs in chunks outside a ticking area still count toward population control counts as long as they were previously loaded (i.e. within [[simulation distance]] at some time) after relogging. The population control caps are split up into two distinct categories: a cap for surface mobs, and a cap for cave mobs. Cave mobs do not count toward the surface mob cap, and surface mobs do not count toward the cave mob cap. Whether a mob counts as a surface mob or a cave mob is determined by where or how it spawned, not where it happens to be at the moment. For cluster spawns, those that spawn on the highest spawnable block at a given coordinate count toward the surface cap, and any that spawn below the highest solid ''or'' non-solid but spawnable (e.g. ice or upper slab with air above) block count toward the cave cap. Structure-spawned mobs and converted mobs (i.e. drowned converted from zombies, witches from villagers, zombified piglins from pigs, and medium and small slimes from killed larger slimes) always count toward the cave cap, and monster-spawner-spawned mobs always count toward the surface cap.

There are five categories of mobs: ambient, animal, monster, pillager, and water_animal. The population control cap for each category and location of mob in each dimension is as follows (* denotes values that are coded in the game but not actually used by any mobs):
{| class="wikitable list-style-none" data-description="Mob Density Caps"
|+Population control caps
!Category
!Location
!Overworld
!Nether
!The End
|-
! rowspan="2" |Ambient
!Surface
|0
|0
|0
|-
!Cave
|2
|0
|2*
|-
! rowspan="2" |Animal
!Surface
|4
|0
|4*
|-
!Cave
|0
|4
|0
|-
! rowspan="2" |Monster
!Surface
|8
|0
|10
|-
!Cave
|16
|16
|8*
|-
! rowspan="2" |Pillager
!Surface
|8
|0
|8*
|-
!Cave
|8
|0
|8*
|-
! rowspan="2" |Water_Animal
!Surface
|36
|0
|36*
|-
!Cave
|0
|0
|0
|}
Some specific mobs types also have their own density caps. The density caps limit the number of those mobs to some amount below the applicable population control cap. Density caps are checked in the same manner as the population control caps. Caps are below (n/a indicates that the mob does not spawn in that environment at all).
{| class="wikitable list-style-none" data-description="Individual mob caps"
|+Mob density caps
!Mob
!Surface cap
!Cave cap
|-
!{{EntityLink|Cod}}
|20
|n/a
|-
!{{EntityLink|Creeper}}
|5
|unlimited (population control cap still applies)
|-
!{{EntityLink|Dolphin}}
|5
|n/a
|-
!{{EntityLink|Drowned}}
|5 in ocean
2 in river
|n/a
|-
!{{EntityLink|Ghast}}
|n/a
|2
|-
!{{EntityLink|Phantom}}
|5
|n/a
|-
!{{EntityLink|Pufferfish}}
|3
|n/a
|-
!{{EntityLink|Salmon}}
|10 in ocean
4 in river
|n/a
|-
!{{EntityLink|Squid}}
|4 in ocean
2 in river
|n/a
|-
!{{EntityLink|Tropical Fish}}
|20 for preset pattern
20 for random pattern
|n/a
|}

==== Bedrock spawn conditions ====
{{see also|Simulation Distance}}The following rules apply to most mobs:

* Mobs spawn at a distance from the player that depends on the world's [[simulation distance]]:
** Simulation distance 4: between 24 and 44 blocks spherical radius from the player.
** Simulation distance 6 and up: between 24 and 128 blocks spherical radius from the player, but limited horizontally by simulation distance and coding that restricts the spawning algorithm from running in chunks whose center exceeds 96 blocks from the player.<ref>The 96-block horizontal limit is reported as a bug at [[bugtracker:MCPE-102197|MCPE-102197]]</ref>
* The bottom part of the mob (i.e. the feet of a standing mob) can spawn only ''in'' an air block, or for water mobs ''in'' a water block. A few naturally-generated, non-motion-blocking blocks such as grass and flowers are ignored for this rule. If the mob spawns in a flower the block above the flower must be air.
* The bounding box of the mob must not intersect any solid blocks. Mobs can spawn intersecting leaves, glass, and other transparent blocks.
* There must be a block with a full, solid top surface under the spawn location for the mob to spawn ''on''. (I.e. mobs cannot spawn on carpets, lower slabs, fences, right-side-up stairs, redstone repeaters, chests, etc.)
* Mobs cannot spawn on transparent full blocks like glass and leaves.
* For mobs that can spawn floating in water or flying in air, the block that is checked for spawning is the water or air block immediately above the first solid top surface block below the spot where the mob would spawn. (So for example, phantoms cannot spawn over a field covered in carpet, and fish cannot spawn in an ocean where bottom slabs cover the ocean floor.)
* Most overworld monsters cannot spawn if the sky light level is greater than or equal to 7 or the block light level is greater than 0.
* Most overworld animals cannot spawn if the (combined) light level is less than 7.

==== Cluster spawning ====
Cluster spawning happens in two stages: first attempt to spawn surface mobs, then attempt to spawn cave mobs. Before spawning, the population control cap is calculated based on the 9 chunk x 9 chunk square area surrounding the current chunk. Spawning begins by picking a random X and Z location within the chunk currently being evaluated. The Y coordinate is determined by starting at the world height and searching downward for a solid-top-surface block with a non-spawn-blocking block above it. The first such block that is found is considered to be the surface, and the algorithm attempts to spawn a surface mob herd. However, if the algorithm finds a solid block before finding a spawnable solid-top-block (e.g. if it finds a tree trunk directly under leaves), it does not make any surface spawn attempt. The algorithm then continues to search downward for the next suitable block with a non-spawn-blocking block above it. When a block meeting the criteria is found, the algorithm attempts to spawn a cave mob herd at that block location. Cave spawn attempts continue until the Y coordinate reaches the world bottom, and do not stop even if a cave herd was spawned.

Surface and cave cluster spawn attempts then go through the following steps to figure out what mob to spawn and how many:

# Picks a random mob.
#* If the current spawn location is in a liquid, pick a random water mob.
#* If the light level is 7 or higher, there are no other blocks above the current location, and the current location is a grass block, pick a random animal mob.
#* Otherwise, spawn a monster mob.
# Picks a random number of mobs to spawn in the herd. Each mob can have its own min and max herd size, and the herd size can depend on difficulty and biome.
# Make sure the spawn location has suitable [[Spawn#Spawn Conditions 2|spawn conditions]].
# Limit the number of mobs spawning based on the global mob cap. No mobs spawn if the mob count already meets or exceeds the mob cap.
# For each mob to spawn, check that spawning it would not exceed the population control cap or mob density cap.
#* If spawning the mob would not exceed the population control or mob density caps, then the probability of a mob spawning can be calculated using the formula: <code>(mob density cap - current mob density count) / mob density cap</code>
# Finally, attempt to spawn the mob in the world.
#* Spawning the mob can fail; for example, if spawning it would cause it to spawn inside of a block or part of a wall.

==== Structure spawning ====
Structure spawn attempts occur at specific relative X and Z coordinates in naturally generated structures, known as "hard-coded spawn spots". The structures that have hard-coded spawn spots include swamp huts, ocean monuments, pillager outposts, and nether fortresses. Whenever a successful cluster spawn attempt occurs within a chunk that contains a hard-coded spawn spot, the environmental spawning algorithm also attempts a structure spawn. (Note that a "successful attempt" here means that a spawnable block was found, even if the spawn was then blocked by light level check or mob cap check.) The structure spawn attempt follows the same rules and steps described above for cluster spawning, with the following changes:

* Instead of starting at world height and searching down to bedrock at the specific X and Z location, the search begins and ends at a specific Y values determined by the type of structure. Structure spawn attempts occur only on the first spawnable block found (i.e. the highest spawnable block) within that range.
* The mob picked depends on the structure: swamp huts spawn witches, ocean monuments spawn guardians, pillager outposts spawn pillagers (including patrol captains), and nether fortresses spawn skeletons, wither skeletons, blazes, and magma cubes.
* The population control caps are effectively 1 higher for structure spawn attempts.

== Other types of spawning ==

=== General ===

* In [[Creative]] or via a dispenser, the player can use [[Spawn egg|spawn eggs]] to spawn most mobs. When mobs are spawned this way, all normal spawning requirements, such as light level and block type, are ignored (though monsters other than shulkers and the ender dragon still cannot be spawned in peaceful).
* Any [[entity]] can be spawned using the {{cmd|summon}} command.

=== Passive mobs ===
{| class="wikitable" data-description="Animals"
!Mob
!Spawning
|-
|
* {{EntityLink|Agent}}
|An agent spawns when using a code connection.{{only|bedrock|education}}
|-
|
* {{EntityLink|Axolotl}}
* {{EntityLink|Cod}}
* {{EntityLink|Salmon}}
* {{EntityLink|Pufferfish}}
* {{EntityLink|Tadpole}}
* {{EntityLink|Tropical Fish}}
|Spawn when using the corresponding [[bucket of aquatic mob]].
|-
|
* {{EntityLink|Bee}}
|Spawn when a [[bee nest]] or beehive is broken without [[Silk Touch]].
|-
|
* {{EntityLink|Brown Mooshroom}}
|Spawns when a [[Mooshroom|red mooshroom]] is struck by lightning, and vice-versa.
|-
|
* {{EntityLink|Cat}}
|Spawns in the vicinity of a player near a village.
|-
|
* {{EntityLink|Chicken}}
|A thrown [[egg]] spawns baby chickens.
|-
|
* {{EntityLink|Iron Golem}}
* {{EntityLink|Snow Golem}}
|Can be made to spawn if a player builds the proper structure out of blocks. They can also be created by an enderman.
|-
|
* {{EntityLink|Mule}}
|Spawn when breeding a horse and a donkey.
|-
|
* {{EntityLink|NPC}}
|Are part of Tutorial Worlds.{{only|education}}
|-
|
* {{EntityLink|Skeleton Horse}}
|Can spawn during thunderstorms, trigger a skeleton trap.
|-
|
* {{EntityLink|Sniffer}}
|[[Sniffer egg|Sniffer eggs]] hatch and spawn snifflets.
|-
|
* {{EntityLink|Turtle}}
|[[Turtle egg|Turtle eggs]] hatch and spawn baby turtles.
|}

=== Hostile mobs ===
{| class="wikitable" data-description="Monsters"
!Mob
!Spawning
|-
|
* {{EntityLink|Blaze}}
* {{EntityLink|Cave Spider}}
* {{EntityLink|Magma Cube}}
* {{EntityLink|Silverfish}}
* {{EntityLink|Skeleton}}
* {{EntityLink|Spider}}
* {{EntityLink|Zombie}}
|A [[monster spawner]] causes mobs to spawn constantly in the area around it.
|-
|
* {{EntityLink|Bogged}}
* {{EntityLink|Breeze}}
* {{EntityLink|Cave Spider}}
* {{EntityLink|Husk}}
* {{EntityLink|Skeleton}}
* {{EntityLink|Silverfish}}
* {{EntityLink|Slime}}
* {{EntityLink|Spider}}
* {{EntityLink|Stray}}
* {{EntityLink|Zombie}}
* {{EntityLink|Zombie}} (Baby)
|A [[trial spawner]] or [[ominous trial spawner]] causes their respective mob to spawn during a normal Trial or an [[ominous trial]].
|-
|
* {{EntityLink|Charged Creeper}}
|If a [[creeper]] gets struck by [[lightning]], it becomes [[Creeper#Charged Creepers|charged]].
|-
|
* {{EntityLink|Creaking}}
|A [[creaking heart]] found in the [[pale garden]] needs to be placed by 2 correctly orientated pale oak logs. When met these conditions, they will activate and spawn a creaking during the night.
|-
|
* {{EntityLink|Endermite}}
|Can spawn randomly when a player uses an [[ender pearl]].
|-
|
* {{EntityLink|Evoker}}
* {{EntityLink|Pillager}}
* {{EntityLink|Ravager}}
* {{EntityLink|Vindicator}}
* {{EntityLink|Witch}}
|Can spawn as part of [[Raid|raids]] or [[Patrol|patrols]].
|-
|
* {{EntityLink|Phantom}}
|Can spawn [[Phantom#Spawning|after player does not sleep or die for at least 3 days]]. ({{IN|bedrock}} phantoms are spawned by the environmental spawning algorithm like other monsters. They are subject to the monster cap, and they count toward the monster cap).
|-
|
* {{EntityLink|Magma Cube}}
* {{EntityLink|Slime}}
|Killing medium and large [[Slime|slimes]] or [[Magma cube|magma cubes]] spawns 2-4 more, but in a smaller size.
|-
|
* {{EntityLink|Silverfish}} (Effect)
|Entities with the [[Effect|Status Effect]] [[Infested]] have a 10% chance to spawn 1-2 silverfish when hurt.
|-
|
* {{EntityLink|Silverfish}} (Block)
|An [[infested block]] spawns a silverfish if broken, or if a nearby silverfish is attacked.
|-
|
* {{EntityLink|Slime}}
|Entities with the [[Effect|Status Effect]] [[Oozing]] will spawn 2 medium Slimes on [[Death]].
|-
|
* {{EntityLink|Skeleton}}
|Skeletons spawn as 20% of naturally-spawning strays.
|-
|
* {{EntityLink|Skeleton Horseman}}
|Spawn from skeleton traps.
|-
|
* {{EntityLink|Warden}}
|When a player activates a naturally generated sculk shrieker four times or more.
|-
|
* {{EntityLink|Witch}}
|When a [[villager]] gets struck by lightning, it is replaced by a newly spawned [[witch]].
|-
|
* {{EntityLink|Wither}}
|Can be made to spawn if a player builds the proper structure out of blocks.
|-
|
* {{EntityLink|Zombie}}
|Zombies spawn as 20% of naturally-spawning husks.{{only|java|short=1}}
|-
|
* {{EntityLink|Zombie}}
* {{EntityLink|Zombified Piglin}}
* {{EntityLink|Illager|id=Evoker}}
|Can spawn reinforcement when hurt{{only|java|short=1}}.
|-
|
* {{EntityLink|Zombie Villager}}
|Zombie villagers spawn as 5% of naturally-spawning zombies.
A villager killed by a zombie has a 50% chance of becoming a zombie villager in normal difficulty, and 100% chance in hard difficulty.
|-
|
* {{EntityLink|Zombified Piglin}}
|Can spawn from [[Nether portal|nether portals]] in the Overworld. Lighting and player proximity don't prevent this.
When a [[pig]] gets struck by [[lightning]], it is replaced by a newly spawned [[zombified piglin]].
|-
|
* {{EntityLink|Zoglin}}
* {{EntityLink|Zombified Piglin}}
|If a [[piglin]] or [[hoglin]] is transported to the [[Overworld]] or [[the End]], after 15 seconds they transform into [[Zombified piglin|zombified piglins]] or [[Zoglin|zoglins]], respectively.
|}

== Despawning ==
{{About|Mob Despawning|Item Despawning|Item#Behavior}}

=== ''Java Edition'' ===
[[File:Mob_spawning_ranges.png|thumb|Various mob spawning ranges, illustrated.]]
All monster, ambient, and aquatic mobs excluding [[Shulker|shulkers]], [[Wither|withers]], [[Elder guardian|elder guardians]] and [[Ender dragon|ender dragons]] despawn unless they have been marked persistent. Other mobs that are not monster, ambient, or aquatic that do despawn include [[Ocelot|ocelots]], stray [[Cat|cats]], [[Wandering trader|wandering traders]], and untamed [[Trader llama|trader llamas]].

* A mob that has had no player within 32 blocks of it for more than 30 seconds, or 10 seconds if in high light levels (over 12) for monsters, has a {{frac|1|800}} chance of despawning on each game [[tick]] ({{frac|1|20}} of a second), which is a 2.47% chance per second. Therefore, the mob population declines so that half remains after 27.75 seconds, and the average lifetime of monsters not within 32 blocks of a player is 40 seconds (after the initial 30 seconds have elapsed). The game uses an inactivity counter to tell wether a mob should be despawned or not.
** The inactivity counter is used to track how long a mob has not taken any action. It also controls whether certain monsters can walk randomly. When the inactivity counter is over 100, all mobs except [[Iron Golem|iron golems]], [[Villager|villagers]], [[Axolotl|axolotls]], [[Camel|camels]], [[Frog|frogs]], [[Goat|goats]], [[Sniffer|sniffers]], [[Hoglin|hoglins]], [[Zoglin|zoglins]], [[Piglin|piglins]], [[Piglin Brute|piglin brutes]], [[Warden|wardens]], and [[Breeze|breezes]] will not walk randomly.
*** The inactivity counter increases by 1 per game tick for all mosters, plus an additional 2 per game tick for mobs with an [[internal light level]] over 12, and an additional 2 per game tick for all [[Illagers|illagers and their allies]]. The inactivity counter is reset if one of the following conditions is met:
**** The mob is less than 32 blocks from the nearest player.
**** The mob is damaged, regardless of the damage type, which resets the counter.
**** The mob is the [[wither]].
**** [[Pillager|Pillagers]], [[Piglin|piglins]] pull their crossbows.
**** [[Illager|Illagers]] target [[Iron Golems|iron golems]] and players during [[Raid|raids]].
**** [[Illager|Illagers]] sweep through villages during [[Raid|raids]].
**** [[Vindicator|Vindicators]] break down doors.
*** Due to the existence of the inactivity counter, mobs outside 32 blocks but within 128 blocks have a minimum survival time. For normal mobs that can be despawned, they can only be despawned after being 32 blocks away from the player for 600 game ticks (30 seconds), and will be despawned after an average of 1400 game ticks (70 seconds); for [[Illager|illagers]], [[Ravager|ravagers]], [[Vex|vexes]], [[Witch|witches]], and monsters in bright places that can be despawned, they can only be despawned after being 32 blocks away from the player for at least 200 game ticks (10 seconds), and will be despawned after an average of 1000 game ticks (50 seconds).
* Mobs other than fish despawn immediately if no player is within 128 blocks of it, while fish despawn if no player is within 64 blocks.<ref name="20w10a" />
** This is a Euclidean sphere, not a cylinder from map top to bottom and not a [[Taxicab distance|taxicab]] sphere (an octahedron). Example: A mob at 0/y/0 remains at least 10 seconds (as above) if the player moves to 65/y/65 (real distance 91.9), but despawns immediately if the player moves to 91/y/91 (real distance 128.7).
** The [[chunk]] the mob is in must still be loaded for the mob to despawn. Otherwise, the mob is saved until the [[Chunk#Chunk loading|chunk is loaded]] again. For example, if a player enters a [[nether portal]] while being chased by a spider, the spider is saved, and it resumes chasing the player coming back through the same portal. In the case of a player reloading chunks, the loading happens before the player is added, meaning they may despawn.
* Ocelots and most monster mobs (including those that are holding items) despawn if the difficulty is set to Peaceful, regardless of where the player is located. Monster mobs that do not despawn include hoglins, piglins, and shulkers in all editions, as well as piglin brutes in ''Bedrock Edition''.
* For despawning to occur, there must be at least one non-spectator player in the dimension.
* Chickens that originally spawned as [[Chicken jockey|chicken jockeys]] follow zombie despawn rules, rather than chicken despawn rules.
* Wandering traders and trader llamas despawn after 40-60 minutes (2-3 in game days). They also despawn sooner if all the trades are locked.{{only|bedrock}}{{verify|This is not true in Java 1.19.2. Is it in Bedrock, or is this outdated or made up?|edition=bedrock}}
* Endermites despawn after 2 minutes unless named with a name tag or have persistent tag.
* Wardens despawn after 1 minute if they couldn't detect a vibration or smell by any mob or player.

{{Anchor|Java persistent mobs}}

Mobs are persistent, meaning they do not despawn and do not count toward the mob cap, when they:

* are a passenger to another mob.
* are riding a [[boat]] or a [[minecart]].<ref>{{bug|MC-182897||Some passenger mobs don't count to the mob cap|WAI}}</ref>
* spawned as part of a [[generated structure]].
* have had something added to their [[inventory]], including having something [[Dispense|dispensed]] upon them (such as a [[saddle]]) or something they have picked up, but never for anything they spawn with. This includes dolphins playing with items{{verify}}.
* have been named with a [[name tag]]. However, one created from a renamed [[spawn egg]] does despawn as normal.
* have had the NBT tag <code>{PersistenceRequired: 1b}</code> set on them, whether by being summoned with it, or by being set manually with {{cmd|data merge}} or {{cmd|data modify}}{{only|java|short=y}}. This is also the only way to prevent wandering traders from despawning.

Following mobs also have another way to prevent despawning and do not count toward mob cap:

* [[Enderman]]: During the time that they hold a block
* [[Fish]] (all variants), [[Axolotl|axolotls]] and [[Tadpole|tadpoles]]: Spawned as a result of placing out of a [[bucket of mob]].
* [[Zombie villager|Zombie villagers]]: If they were converted from a [[villager]] that has been traded with. This still counts toward the hostile mob cap.<ref>{{bug|MC-182304}}</ref>
* [[Zombified piglin|Zombified piglins]] and [[Witch|witches]]: If they were converted from a [[pig]] or [[villager]] struck by lightning.
* [[Hoglin|Hoglins]]: If a [[crimson fungus]] is {{control|used}} on them. [[Zoglin|Zoglins]] as a result of hoglins have crimson fungus {{control|used}} on them before they zombify also do not despawn.

=== ''Bedrock Edition'' ===
{{IN|be}}, like Java, despawning occurs based on distance and chance.

* On simulation distances 6 and higher, almost all environmentally spawned mobs immediately despawn when they are either (1) in a chunk at the edge of the simulation distance (technically, a chunk not fully surrounded by 8 chunks that were simulated on the last game tick), or (2) more than 128 blocks from the nearest player.
* On simulation distance 4, mobs immediately despawn when they are more than 44 blocks from the nearest player.
* [[Fish]] despawn at a shorter distance, when they are more than 40 blocks from the nearest player on all simulation distances.
* Mobs more than 32 blocks from the nearest player have a 1 in 800 chance to despawn on each game tick if they have not taken damage for 30 seconds.

Mobs with persistence do not despawn. Mobs gain persistence in the following ways:

* The entity interacts with a player (except for attacking, which does not count as a persistence-inducing interaction):
** Is ridden by the player.
** Is named with a [[name tag]].
** Is tempted with [[food]].
** Is [[bred]], or born as a result of breeding (except for turtles hatched from eggs before 1.17.10 <ref>{{bug|MCPE-70664}}</ref>).
** Is tamed by the player.
** Is summoned using the {{cmd|summon}} command or a spawn egg.
** Is [[Zombie Villager#Curing|cured from being a zombie villager]].
** Is spawned by the player triggering a [[skeleton trap]] (spawns [[Skeleton|skeletons]] and [[Skeleton horse|skeleton horses]]).
* The entity picks up an item.
* The entity is spawned during the generation of a certain kind of [[structure]]:
** [[Shulker]] spawned in an [[end city]].
** [[Witch]] spawned in a [[swamp hut]].
** [[Villager]] or [[zombie villager]] spawned in an [[igloo]].
** Villager or animals spawned in a village.
** Zombie villager or animals spawned in a [[zombie village]].
** [[Vindicator]] or [[evoker]] spawned in a [[woodland mansion]].
* The entity is spawned in a raid.

The following entities always have persistence:{{columns-list|* {{EntityLink|Ender Dragon}}
* {{EntityLink|Item Frame}}
* {{EntityLink|Wither}}
* {{EntityLink|Elder Guardian}}
* {{EntityLink|Evoker}}
* {{EntityLink|Vindicator}}
* {{EntityLink|Iron Golem}}
* {{EntityLink|Snow Golem}}
* {{EntityLink|Villager}}
* {{EntityLink|Armor Stand}}
* {{EntityLink|Sniffer}}
* {{EntityLink|Minecart}}
* {{EntityLink|Painting}}
* {{EntityLink|Shulker}}
* {{EntityLink|Agent}}{{only|bedrock|education|short=1}}
* {{EntityLink|Camera}}{{only|bedrock|education|short=1}}
* {{EntityLink|NPC}}{{only|bedrock|education|short=1}}
}}

== History ==
{{HistoryTable
|{{HistoryLine|java classic|}}
|{{HistoryLine||August 25, 2009|link=https://notch.tumblr.com/post/170887079/survival-mode-status-update-video-with-plenty-of|Mobs shown to spawn in groups.}}
|{{HistoryLine|java indev}}
|{{HistoryLine||0.31|dev=20100204-2027|Mob spawning is now determined by [[light]] level. Hostile mobs spawn only in dark areas, and passive mobs spawn only in bright areas.}}
|{{HistoryLine|java alpha}}
|{{HistoryLine||v1.2.0|dev=<nowiki>?</nowiki>|slink=:Category:Information needed requiring unarchived version|The mob spawning algorithm has been changed. Trying to spawn mobs inside a solid block no longer causes that entire spawn cycle to bail out.
|The chunk 0,0 (X 0-15 and Z 0-15) is no longer always the first chunk evaluated for mob spawning. Previously, if one built a dark room inside that chunk, almost all mobs would spawn there as there was no chance of the algorithm bailing out before reaching that chunk.
|Hostile mobs can now spawn in higher light levels at lower depths, using the formula 16 − (Layer / 8). At level 8 and below, mobs could spawn even in sunlight.}}
|{{HistoryLine||v1.2.1|Hostile mobs can no longer spawn in higher light levels at lower depths.}}
|{{HistoryLine||unknown|The spawning area used to be 17x17 chunks rather than 15x15. The area was reduced, but the old size is still used to calculate mob caps.
|It was not always possible to funnel mobs into a spawning room by preventing them from spawning elsewhere. Some older sources of information about spawning might make reference to this.
|Large amounts of empty space used to encourage spawning in the general area. This remains true on a smaller scale, and only horizontally, due to pack spawning.}}
|{{HistoryLine|java beta}}
|{{HistoryLine||1.8|dev=Pre-release|Previously, mob spawning was determined by light level rather than the current chunk properties. This was no longer the case in Beta 1.8. In a pre-Beta 1.8 world, hostile mobs would spawn in light level 7 or lower while friendly mobs would spawn in light levels 9 or higher. Because of this, hostile mobs had a slight chance of spawning even though it was light due to them spawning in the air where there was little light. If you had a lot of torches down, go down to your mine, then return, you would have a tendency to find your house having some cows, pigs, chickens or sheep running about.}}
|{{HistoryLine|java}}
|{{HistoryLine||1.4.2|dev=12w32a|Added the [[game rule]] <code>doMobSpawning</code> to toggle mob spawning.}}
|{{HistoryLine||1.8|dev=14w25a|Most restrictions on the pack location are removed. Formerly it had to be an air block, now any non-opaque block suffices.}}
|{{HistoryLine||1.9|dev=15w46a|When spawning mobs, the spawning block cannot block movement (formerly just had to be non-opaque) and cannot be any type of [[rail]]. Also the block above can no longer be liquid.}}
|{{HistoryLine|||dev=pre2|Pack spawning mechanics adjusted, "12 attempts" is now "up to 12 attempts" and is even more heavily weighted toward the center.}}
|{{HistoryLine||1.15|dev=19w37a|When breedable mobs spawn naturally in a group, the group now sometimes includes babies. (Has a 5% or 10% chance depending on the animal.)}}
|{{HistoryLine||1.16|dev=20w18a|Mobs that are riders of other mobs and entities (like [[boat]]s and [[minecart]]s) no longer despawn.
|Added the spawn cost/charge system that reduces hostile mob spawn rates in [[soul sand valley]] and [[warped forest]].
|Added a new section to the [[debug screen]], which covers the spawning of mobs in each category.}}
|{{HistoryLine||1.17|dev=21w13a|Added a new mob cap category for [[axolotl]]s and [[glow squid]]s.}}
|{{HistoryLine||1.18|dev=Experimental Snapshot 1|Hostile mobs now spawn only in light level 0.}}
|{{HistoryLine|||dev=experimental snapshot 3|Mob spawning is now consistent at all [[altitude]]s, making spawn rates at all Y-levels approximately equal to the previous spawn rate at Y{{=}}64.
|Added per-player mob caps.}}
|{{HistoryLine|||dev=experimental snapshot 5|The spawn rate changes in experimental snapshot 3 have been reverted.}}
|{{HistoryLine|||dev=21w37a|[[Axolotl]]s now have their own mob cap, separate from [[glow squid]]s.}}
|{{HistoryLine|||dev=21w40a|Axolotls now spawn only when there is a clay block less than five blocks below the spawning space.}}
|{{HistoryLine||1.18.2|dev=22w07a|Aquatic mobs now spawn only if the block above is a non-waterlogged water block, preventing fish from spawning inside bubble elevators.}}
|{{HistoryLine|console}}
|{{HistoryLine||xbox=TU1|xbone=CU1|ps3=1.00|psvita=1.00|ps4=1.00|wiiu=Patch 1|switch=1.0.1|Added mob spawning.}}
|{{HistoryLine||xbox=?|xbone=?|ps3=?|psvita=?|ps4=?|wiiu=?|switch=1.0.1|Added a mob spawning [[host options|host option]].{{info needed|Was this added in TU19?}}}}
|{{HistoryLine||xbox=TU46|xbone=CU36|ps3=1.38|psvita=1.38|ps4=1.38|wiiu=Patch 15|switch=1.0.1|Mobs no longer spawn on rails.}}
}}

== Issues ==
{{issue list}}

== Trivia ==

* In ''Bedrock Edition'', an opaque block normally causes all blocks below it to spawn cave mobs, but not if a transparent block is placed on top.

== References ==
{{Message box
| text = This might have refrences from when "Spawn" was just a single page covering both mob- and player spawning
}}<references />

== External links ==

* [http://www.minecraftforum.net/topic/136723-mob-spawning-algorithm-in-12-01-analyzed/ Forum thread by Marglyph] about the spawning algorithm in [[Java Edition Beta 1.2|Beta 1.2]]
* [http://www.minecraftforum.net/topic/37979-mob-spawning-science/ Forum thread by fr0stbyte124] on mob spawning in [[Java Edition Alpha v1.1.2 01|Alpha v1.1.2_01]] from before the [[Halloween Update]] changes

== Navigation ==
{{Navbox gameplay}}
