# Why size of Option\<&usize\> is 8?

**URL:** <https://users.rust-lang.org/t/why-size-of-option-usize-is-8/142435>\
**Category:** uncategorized\
**Created:** [September 15, 2026, 6:36pm UTC](https://users.rust-lang.org/t/why-size-of-option-usize-is-8/142435 "2026-09-15T18:36:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zugzwanged](https://avatars.discourse-cdn.com/v4/letter/z/ba8739/32.png) [@zugzwanged](https://users.rust-lang.org/u/zugzwanged)\
**Post date:** [September 15, 2026, 6:36pm UTC](https://users.rust-lang.org/t/why-size-of-option-usize-is-8/142435/1 "2026-09-15T18:36:30Z")

</div>

Hi folks! Why does the first line print 8? Also, the scond line prints 16, is that because Option contains two variants Some and None which is equivalent to containing two usize (discriminant)?

```rust
fn main() {
  dbg!(size_of::<Option<&usize>>());
  dbg!(size_of::<Option<usize>>());
}

```

---

<div class="post-metadata">

**Author:** ![blonk](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/blonk/32/38259_2.png) [@blonk](https://users.rust-lang.org/u/blonk)\
**Post date:** [September 15, 2026, 6:43pm UTC](https://users.rust-lang.org/t/why-size-of-option-usize-is-8/142435/2 "2026-09-15T18:43:55Z")

</div>

`&usize` can't be "null" (`0`), so `Option` can use that value to represent the `None` case. In the second case it needs to store the `Some`/`None` distinction in another memory location.

You can use your favorite search engine to search for "rust niche optimization" to read more about it.

Edit: Just discovered [niche.rs](https://niche.rs/)

---

<div class="post-metadata">

**Author:** ![quinedot](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/quinedot/32/17693_2.png) [@quinedot](https://users.rust-lang.org/u/quinedot)\
**Post date:** [September 15, 2026, 7:22pm UTC](https://users.rust-lang.org/t/why-size-of-option-usize-is-8/142435/3 "2026-09-15T19:22:23Z")

</div>

Note that while [the representation is guaranteed for a specific list of types,](https://doc.rust-lang.org/std/option/index.html#representation) there aren't many guarantees beyond that. So for other types, you may see e.g. size differences between ~~editions~~ versions because the niche algorithm changed or such.

And for questions like

> [@zugzwanged](#):
>
> Also, the scond line prints 16, is that because Option contains two variants Some and None which is equivalent to containing two usize (discriminant)?

one can point out that 8 bytes isn't enough to distinguish all the possible values, and that the `usize` must be stored in an aligned location (you can get a reference to it without removing it from the `Option`), so the size must be a multiple of 8 which is greater than 8.

But _exactly_ how the discriminant is stored\[1\] is an implementation detail.

* * *

1. is it a `usize`, is it a byte, which byte, what values...

---

<div class="post-metadata">

**Author:** ![chrefr](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@chrefr](https://users.rust-lang.org/u/chrefr)\
**Post date:** [September 15, 2026, 7:33pm UTC](https://users.rust-lang.org/t/why-size-of-option-usize-is-8/142435/4 "2026-09-15T19:33:39Z")

</div>

> [@quinedot](#):
>
> So for other types, you may see e.g. size differences between editions because the niche algorithm changed or such

Not really editions because they need to interoperate (while the compiler could technically save the edition of the type, it doesn't currently). But versions of the compiler, sure.

---

<div class="post-metadata">

**Author:** ![chrefr](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@chrefr](https://users.rust-lang.org/u/chrefr)\
**Post date:** [September 15, 2026, 7:35pm UTC](https://users.rust-lang.org/t/why-size-of-option-usize-is-8/142435/5 "2026-09-15T19:35:06Z")

</div>

> [@blonk](#):
>
> Edit: Just discovered [niche.rs](https://niche.rs/)

Nice site, but note that rust-analyzer has a command "rust-analyzer: View Memory Layout" (on VSCode) that does basically the same.

---

<div class="post-metadata">

**Author:** ![quinedot](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/quinedot/32/17693_2.png) [@quinedot](https://users.rust-lang.org/u/quinedot)\
**Post date:** [September 15, 2026, 7:37pm UTC](https://users.rust-lang.org/t/why-size-of-option-usize-is-8/142435/6 "2026-09-15T19:37:35Z")

</div>

Whoops, yep, that is what I meant. Thanks!
